Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cctype>
- #include <ctime>
- #include <functional>
- #include <iostream>
- #include <random>
- #include <string>
- #include <vector>
- #include <windows.h>
- void cls()
- {
- HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
- COORD coordScreen = { 0, 0 };
- DWORD cCharsWritten;
- CONSOLE_SCREEN_BUFFER_INFO csbi;
- DWORD dwConSize;
- if( !GetConsoleScreenBufferInfo( hConsole, &csbi ))
- return;
- dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
- if( !FillConsoleOutputCharacter( hConsole, (TCHAR) ' ', dwConSize, coordScreen, &cCharsWritten ) ||
- !GetConsoleScreenBufferInfo( hConsole, &csbi ) ||
- !FillConsoleOutputAttribute( hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten ))
- return;
- SetConsoleCursorPosition( hConsole, coordScreen );
- }
- template <typename T>
- T read(const std::string& request)
- {
- std::cout << request;
- T value;
- bool repeat = true;
- while (repeat)
- {
- repeat = false;
- std::cin >> value;
- if(!std::cin)
- {
- std::cout << "Invalid input\n";
- std::cin.clear();
- repeat = true;
- while(!isspace(std::cin.get()))
- ;
- }
- }
- return value;
- }
- bool ask(const std::string& question)
- {
- std::cout << question << '\n';
- char c;
- do
- {
- c = tolower(read<char>(""));
- if(c != 'y' && c != 'n')
- std::cout << "Invalid answer. Only Y, y, N and n are allowed\n";
- }
- while(c != 'y' && c != 'n');
- return c == 'y';
- }
- void application5()
- {
- int number,guess;
- while(number!=guess)
- {
- do
- {
- cls();
- std::cout<<"Enter a number 13 to 17\n";
- std::cin>>number;
- switch(number)
- {
- case 13:
- {
- number=number*7.5433;
- break;
- }
- case 14:
- {
- number=number*3.9433;
- break;
- }
- case 15:
- {
- number=number*11.2433;
- break;
- }
- case 16:
- {
- number=number*4.69433;
- break;
- }
- case 17:
- {
- number=number*13.9433;
- break;
- }
- default:
- {
- std::cout<<"You haven't entered 13,14,15,16 or 17";
- }
- }
- cls();
- std::cout<<"Now you must guess the number\n";
- int times=0;
- do
- {
- times++;
- std::cin>>guess;
- if(guess<number)
- {
- std::cout<<"Too small\n";
- }
- if(guess>number)
- {
- std::cout<<"Too hight\n";
- }
- if(guess==number)
- {
- cls();
- std::cout<<"Congratulations1! You discovered the number\n";
- std::cout<<"The number was " << number << "\n"<<std::endl;
- std::cout<<"It took you "<<times<<" times to guess the number.\n\n";
- }
- }
- while(guess<number || guess>number);
- }
- while(ask("Do you want to try again?(Y OR N)"));
- }
- }
- void application4()
- {
- cls();
- int number[5];
- std::cout<<"Enter the number of pancakes eaten for the each Person\n";
- std::cout<<"First person:";
- std::cin>>number[1];
- std::cout<<"Second person:";
- std::cin>>number[2];
- std::cout<<"Third person:";
- std::cin>>number[3];
- std::cout<<"Fourth person:";
- std::cin>>number[4];
- std::cout<<"Fifth person:";
- std::cin>>number[5];
- cls();
- //The most eaten.
- if(number[1]>number[2]&&number[1]>number[3]&&number[1]>number[4]&&number[1]>number[5])
- {
- std::cout<<"First person have eaten the most pancakes ("<< number[1]<< ")\n";
- }
- if(number[2]>number[1]&&number[2]>number[3]&&number[2]>number[4]&&number[2]>number[5])
- {
- std::cout<<"Second person have eaten the most pancakes ("<< number[2]<< ")\n";
- }
- if(number[3]>number[1]&&number[3]>number[2]&&number[3]>number[4]&&number[3]>number[5])
- {
- std::cout<<"Third person have eaten the most pancakes ("<< number[3]<< ")\n";
- }
- if(number[4]>number[1]&&number[4]>number[2]&&number[4]>number[3]&&number[4]>number[5])
- {
- std::cout<<"Fourth person have eaten the most pancakes ("<< number[4]<< ")\n";
- }
- if(number[5]>number[1]&&number[5]>number[2]&&number[5]>number[3]&&number[5]>number[4])
- {
- std::cout<<"Fifth person have eaten the most pancakes ("<< number[5]<< ")\n";
- }
- std::cin.get(); //The fewest eaten;
- if(number[1]<number[2]&&number[1]<number[3]&&number[1]<number[4]&&number[1]<number[5])
- {
- std::cout<<"First person have eaten the fewest pancakes ("<< number[1]<< ")";
- }
- if(number[2]<number[1]&&number[2]<number[3]&&number[2]<number[4]&&number[2]<number[5])
- {
- std::cout<<"Second person have eaten the fewest pancakes ("<< number[2]<< ")";
- }
- if(number[3]<number[1]&&number[3]<number[2]&&number[3]<number[4]&&number[3]<number[5])
- {
- std::cout<<"Third person have eaten the fewest pancakes ("<< number[3]<< ")";
- }
- if(number[4]<number[1]&&number[4]<number[2]&&number[4]<number[3]&&number[4]<number[5])
- {
- std::cout<<"Fourth person have eaten the fewest pancakes ("<< number[4]<< ")";
- }
- if(number[5]<number[1]&&number[5]<number[2]&&number[5]<number[3]&&number[5]<number[4])
- {
- std::cout<<"Fifth person have eaten the fewest pancakes ("<< number[5]<< ")";
- }
- }
- void application3()
- {
- double number;
- int times = 0;
- cls();
- std::cout<<"Please enter a number other than 5\n";
- do
- {
- times++;
- std::cin>>number;
- std::cout<<"Enter a number,other than 5\n";
- }
- while(number !=5&×!=10);
- cls();
- if(times==10)
- {
- std::cout<<"Wow, you're more patient then I am, you win.\n\n";
- }
- else
- {
- std::cout<<"Hey , you weren't supossed to enter 5!\n\n";
- }
- }
- void application2()
- {
- int howmany;
- int choice;
- do
- {
- std::cout<<"There's the list of what you can buy\n";
- std::cout<<"<<--Cola-->>{1}\n<<--Beer-->>{2}\n<<--Sprite-->>{3}\n<<--Wine-->>{4}\n<<--Apple Juice-->>{5}\n";
- std::cin>>choice;
- switch(choice)
- {
- case 1:
- {
- std::cout<<"An bottle of Cola it's 2$, how many do you want?\n";
- std::cin>>howmany;
- std::cout<<"You have to pay " << howmany*2<<" $\n";
- }
- break;
- case 2:
- {
- cls();
- std::cout<<"An bottle of Beer it's 3.3$, how many do you want?\n";
- std::cin>>howmany;
- std::cout<<"You have to pay " << howmany*3.3<<" $\n";
- }
- break;
- case 3:
- {
- cls();
- std::cout<<"An bottle of Sprite it's 1.5$, how many do you want?\n";
- std::cin>>howmany;
- std::cout<<"You have to pay " << howmany*1.5<<" $\n";
- }
- break;
- case 4:
- {
- cls();
- std::cout<<"An bottle of Wine it's 12$, how many do you want?\n";
- std::cin>>howmany;
- std::cout<<"You have to pay " << howmany*12<<" $\n";
- }
- break;
- case 5:
- {
- cls();
- std::cout<<"An bottle of Apple Juice it's 3.8$, how many do you want?\n";
- std::cin>>howmany;
- std::cout<<"You have to pay " << howmany*3.8<<" $\n";
- }
- break;
- }
- }
- while(ask("Do you want to continue?(Y OR N)"));
- }
- void application1()
- {
- int score;
- do
- {
- std::cout<<"Enter you're score of the programming class(0-100)\n)";
- std::cin>>score;
- if(score==100)
- {
- cls();
- std::cout<<"Congratulations! You scored a perfect note.\n";
- }
- if (score>90 && score<99)
- {
- cls();
- std::cout<<"Congratulations! You're note is an A.\n";
- }
- if (score>80 && score<89)
- {
- cls();
- std::cout<<"Congratulations! You're note is an B.\n";
- }
- if (score>70 && score<79)
- {
- cls();
- std::cout<<"Congratulations! You're note is an C.\n";
- }
- if (score>60 && score<69)
- {
- cls();
- std::cout<<"Congratulations! You're note is an D.\n";
- }
- if (score>0 && score<59)
- {
- cls();
- std::cout<<"Congratulations! You're note is an F.\n";
- }
- else
- {
- cls();
- }
- }
- while(ask("Do you want to continue?(Y OR N)"));
- }
- int main()
- {
- int dec;
- {
- std::cout<<" <>-1-<>\n\n";
- std::cout<<" <<---Grading Program--->>\n\n";
- std::cout<<" <>-2-<>\n\n";
- std::cout<<" <<---Cola Machine--->>\n\n";
- std::cout<<" <>-3-<>\n\n";
- std::cout<<" <<---While user == gullible--->>\n\n";
- std::cout<<" <>-4-<>\n\n";
- std::cout<<" <<---Pancakes--->>\n\n";
- std::cout<<" <>-5-<>\n\n";
- std::cout<<" <<---Bracketing Search--->>\n\n";
- std::cin>>dec;
- switch(dec)
- {
- case 1:
- {
- cls();
- application1();
- break;
- }
- case 2:
- {
- cls();
- application2();
- break;
- }
- case 3:
- {
- cls();
- application3();
- break;
- }
- case 4:
- {
- cls();
- application4();
- break;
- }
- case 5:
- {
- cls();
- application5();
- break;
- }
- default:
- {
- cls();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment