
Курсовой Проект C++
.pdfvoid Author::AuthorMenu()//вывод информации об авторе
{
PosScan();
namemenu("Об авторе"); position.X = widht/3;
position.Y = height/2;
for (int i = 0; i < 6; i++, position.Y++)
{
SetConsoleCursorPosition(hstdout, position); cout << Aauthor[i] << endl;
}
PressAnyButton(); _getch();
}
void menu::MenuPosSet(int i)//координаты кнопок
{
position.X = ((widht / 5)*i); position.Y = height / 2;
}
void menu::menuwrite(int i, string str)//вывод кнопок
{
MenuPosSet(i); SetConsoleCursorPosition(hstdout, position); cout << str;
}
void menu::menuchoice(int i)
{
drawchoicer(menuitem); key = _getch();
switch (key)
{
case 27://esc screen = 0;
break;
case 77://стрелка вперед case 39:
case 68: case 100:
Beep(2000, 3);
if (menuitem < i) menuitem++;
else menuitem = 1;
break;
case 75://стрелка назад case 65:
case 37: case 97:
Beep(2000, 3);
if (menuitem > 1) menuitem--;
else menuitem = i;
break;
case 13://Enter
selectionhandler();
break;
default:
menuchoice(i);
}
31
}
void menu::selectionhandler()
{
Beep(2000, 8); switch (menuitem)
{
case 1:
if (screen == 0) screen = 1;
else screen = 5; break;
case 2:
if (screen == 0) screen = 3;
else screen = 4; break;
case 3:
if (screen == 0) screen = 2;
else screen = 0; break;
case 4:
stopping = true; break;
}
}
void menu::namemenu(string name)
{
PosScan();
position.X = (widht / 7)*3; position.Y = height / 3;
SetConsoleCursorPosition(hstdout, position); cout << name << endl;
}
void menu::drawchoicer(int i)
{
MenuPosSet(i); position.X -= 2; drawchoicerside(); position.Y -= 1; drawchoicerflor(); position.Y += 2; drawchoicerflor(); position.Y -= 1; position.X += 15; drawchoicerside();
}
void menu::drawchoicerside()
{
SetConsoleCursorPosition(hstdout, position); cout << "|";
}
void menu::drawchoicerflor()
{
32
SetConsoleCursorPosition(hstdout, position); cout << "----------------";
}
void menu::DrawMainMenu()//отрисовка главного меню
{
namemenu("Главное меню"); menuwrite(1, "Калькуляторы"); menuwrite(2, "Заставка"); menuwrite(3, "Об авторе"); menuwrite(4, "<--Выход"); menuchoice(4);
}
void menu::DrawSubMenu()//отрисовка доп меню
{
namemenu("Калькуляторы"); menuwrite(1, "Кинематика"); menuwrite(2, "Калькулятор"); menuwrite(3, "<--Назад"); menuchoice(3);
}
void menu::CursorVisible(bool t)
{
Cursor.bVisible = t; Cursor.dwSize = 1;
SetConsoleCursorInfo(hstdout, &Cursor);
}
void menu::PosScan()
{
GetConsoleScreenBufferInfo(hstdout, &consoleInfo);
widht = consoleInfo.srWindow.Right - consoleInfo.srWindow.Left + 1; height = consoleInfo.srWindow.Bottom - consoleInfo.srWindow.Top + 1;
}
void menu::PressAnyButton()
{
PosScan();
position.X = widht / 3; position.Y = (height / 5)*4;
SetConsoleCursorPosition(hstdout, position);
cout << "Для возврата нажмите любую кнопку...";
}
bool kinematicscalc::datacheck()
{
Xe = atof(buff[1].c_str()); Ye = atof(buff[2].c_str()); t0 = atof(buff[3].c_str()); if (Ye < 0 or t0 <= 0)
{
cout << "\n\n\nОшибка, некоректные данные!" << endl; _getch();
return false;
}
else return true;
}
33
void kinematicscalc::timeposition(double t)
{
x = U0x * t;
y = (U0y * t) - (g * pow(t, 2))/2;
}
void kinematicscalc::initspeeds()
{
U0x = Xe / t0;
U0y = (Ye + (g*pow(t0, 2))/2)/t0;
}
void kinematicscalc::drawgraph()
{
system("cls"); Cursor.bVisible = t; Cursor.dwSize = 1;
SetConsoleCursorInfo(hstdout, &Cursor); balisticcounter();
infograph(); SelectObject(hdc, Pen);
position.X = (window.right / 2) - (HightmaxX / mp) + (traectory[0].x / mp); position.Y = window.bottom - (traectory[0].y / mp);
for (i = 0; i < colpoint; i++)
{
SelectObject(hdc, Earse);
Ellipse(hdc, position.X - 2, position.Y + 2, position.X + 2, position.Y - 2); position.X = (window.right / 2) - ((Xe/2) / mp) + (traectory[i].x / mp); position.Y = window.bottom -(traectory[i].y / mp);
SelectObject(hdc, Pen);
Ellipse(hdc, position.X - 2, position.Y + 2, position.X + 2, position.Y - 2); Sleep(interval*1000);
pointinfo(traectory[i]);
}
}
void kinematicscalc::infograph()
{
cout << "Х конечное: " << Xe << endl; cout << "Y конечное: " << Ye << endl; cout << "Y макс: " << HightmaxY << endl; cout << "Время: " << t0 << endl;
cout << "Точек: " << colpoint << endl; cout << "U0x: " << U0x << endl;
cout << "U0y: " << U0y << endl;
}
void kinematicscalc::pointinfo(point p)
{
SetConsoleCursorPosition(hstdout, { 0,7 }); cout << "t: " << p.t << endl;
cout << "X: " << p.x << endl; cout << "Y: " << p.y << endl;
}
void kinematicscalc::balisticcounter()
{
WindowSize();
initspeeds();
timeposition(U0y/g);//максимальная высота
34
HightmaxY = y; HightmaxX = x;
double mpY = HightmaxY/(window.bottom - 10);//метров на пиксель по высоте double mpX = abs(Xe)/window.right;//метров на пиксель по ширине
mp = (mpX > mpY) ? mpX : mpY; //размер пикселя в метрах colpoint = (abs(Xe)>HightmaxY)?abs(Xe)/mp:HightmaxY/mp;//кол-во точек interval = t0 / colpoint;//секунд полета на 1 точку
traectory = new point[colpoint];
for (i = 0,t=0; i < colpoint; i++,t+= interval)
{
timeposition(t); traectory[i].t = t; traectory[i].x = x; traectory[i].y = y;
}
}
void kinematicscalc::pointtable()
{
system("cls");
for (i = 0; i < colpoint; i++)
{
cout.width(12);
cout << traectory[i].t << "| "; cout.width(12);
cout << traectory[i].x << "| "; cout.width(12);
cout<< traectory[i].y << endl;
}
_getch(); system("cls");
}
void kinematicscalc::scanquestion()
{
position.X = 3*otrX; for (i = 1; i <= 3; i++)
{
position.Y = otrY * i; SetConsoleCursorPosition(hstdout, position); getline(cin, buff[i]);
}
}
void kinematicscalc::printquestion()
{
cout << question[0]; position.X = otrX; for (i = 1; i <= 3; i++)
{
position.Y = otrY * i; SetConsoleCursorPosition(hstdout, position); cout << question[i];
}
}
void kinematicscalc::WindowSize()
{
GetConsoleScreenBufferInfo(hstdout, &consoleInfo); GetClientRect(hwnd, &window);
35
otrX = (consoleInfo.srWindow.Right - consoleInfo.srWindow.Left + 1) / 5; otrY = (consoleInfo.srWindow.Bottom - consoleInfo.srWindow.Top - 7) / 4;
}
void kinematicscalc::startmenu()
{
do {
system("cls");
WindowSize();
printquestion();
scanquestion(); } while (!datacheck()); drawgraph();
}
void kinematicscalc::endmenu()
{
key = _getch(); switch ((int)key)
{
case 27://выход break;
case 49://повтор system("cls"); drawgraph(); break;
case 50://таблица pointtable(); break;
case 51://ввод данных startmenu();
break;
default:
endmenu();
}
}
void kinematicscalc::input()
{
startmenu(); do {
SetConsoleCursorPosition(hstdout, {0,7});
cout << "ESC - Выход |
" << endl; |
|
cout << " 1 |
- Повтор |
" << endl; |
cout << " 2 |
- Таблица |
" << endl; |
cout << " 3 |
- Новые параметры " << endl; |
endmenu(); } while ((int)key!= 27);
}
void matchcalcs::refreshsize()
{
GetConsoleScreenBufferInfo(hstdout, &consoleInfo);
topleftcorner.X = (consoleInfo.srWindow.Right - consoleInfo.srWindow.Left + 1)/4; topleftcorner.Y = (consoleInfo.srWindow.Bottom - consoleInfo.srWindow.Top + 1) /5; bottomrightcorner.X = topleftcorner.X * 3;
bottomrightcorner.Y = topleftcorner.Y * 4;
}
void matchcalcs::calcdrawe()
{
36
refreshsize();
position = topleftcorner; sideline();
position.X = bottomrightcorner.X; position.Y = topleftcorner.Y; sideline();
position.Y = topleftcorner.Y - 1; position.X = topleftcorner.X + 1; topline();
position.Y = bottomrightcorner.Y; position.X = topleftcorner.X + 1; topline();
position.Y = topleftcorner.Y + 2; position.X = topleftcorner.X + 1; topline();
position.X = topleftcorner.X + 1; position.Y = topleftcorner.Y + 1;
SetConsoleCursorPosition(hstdout, position); cout << out;
keylong = (bottomrightcorner.X - topleftcorner.X) / 6; keyhight = (bottomrightcorner.Y - topleftcorner.Y-2) / 4; sx = keylong / 2 + topleftcorner.X;
sy = 3 + topleftcorner.Y + keyhight / 2; for (i = 0; i < 24; ++i)
{
kayboardpos(i); SetConsoleCursorPosition(hstdout, position); cout << kayboard[i];
if (i == selectedkey)
{
SetConsoleTextAttribute(hstdout, FOREGROUND_RED); position.X -= 2;
dravecursor(); position.X += 6; dravecursor();
SetConsoleTextAttribute(hstdout, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
}
}
}
void matchcalcs::dravecursor()
{
SetConsoleCursorPosition(hstdout, position); cout << "|";
}
void matchcalcs::keyhandler()
{
key = _getch(); Beep(2000, 3); switch (key)
{
case 77://стрелка вперед case 39:
case 68: case 100:
if (selectedkey < 23) selectedkey++;
else selectedkey = 0;
37
break;
case 75://стрелка назад case 65:
case 37: case 97:
if (selectedkey > 0) selectedkey--;
else selectedkey = 23; break;
case 72://стрелка вверх case 119:
if (selectedkey > 5) selectedkey-=6;
else selectedkey = 24 + selectedkey - 6; break;
case 80://стрелка вниз case 115:
if (selectedkey < 18) selectedkey += 6;
else selectedkey = selectedkey - 18; break;
case 27:
break;
case 13:
buttonhandler();
break;
default:
keyhandler();
}
}
void matchcalcs::buttonhandler()
{
switch (selectedkey)
{
case 0://цифры case 1:
case 2: case 6: case 7: case 8: case 12: case 13: case 14: case 18: case 19:
out += kayboard[selectedkey]; break;
case 3://деление case 9://минус case 10://плюс
case 15://умножение number = atof(out.c_str()); out.clear();
operation = selectedkey; break;
case 4://cтереть знак if (!out.empty()) out.resize(out.size() - 1); break;
38
case 5://сброс out.clear(); number = 0; operation = 0; break;
case 11://корень
out = to_string(sqrt(atof(out.c_str()))); break;
case 16://синус
out = to_string(sin(atof(out.c_str()))); break;
case 17://синус
out = to_string(cos(atof(out.c_str()))); break;
case 21://ln
out = to_string(log(atof(out.c_str()))); break;
case 22://tg
out = to_string(tan(atof(out.c_str()))); break;
case 23://ctg
out = to_string(1/tan(atof(out.c_str()))); break;
case 20://равно ToArgOperation(); break;
}
}
void matchcalcs::ToArgOperation()
{
switch (operation)
{
case 3://деление
if (atof(out.c_str())!=0)
out = to_string(number / atof(out.c_str())); number = 0;
break;
case 9://минус
out = to_string(number - atof(out.c_str())); break;
case 10://плюс
out = to_string(number + atof(out.c_str())); break;
case 15://усножение
out = to_string(number * atof(out.c_str())); break;
}
operation = 0;
}
void matchcalcs::sideline()
{
while(position.Y <= bottomrightcorner.Y)
{
dravecursor();
position.Y++;
}
39
}
void matchcalcs::kayboardpos(int i)
{
position.X = sx + keylong * (i % 6); position.Y = sy + keyhight * (i / 6);
}
void matchcalcs::topline()
{
while (position.X < bottomrightcorner.X)
{
SetConsoleCursorPosition(hstdout, position); cout << "_";
position.X++;
}
}
void matchcalcs::calc()
{
do {
system("cls");
calcdrawe();
keyhandler(); } while (key != 27);
}
40