Advertisement
Guest User

Shara prog

a guest
Mar 3rd, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.66 KB | None | 0 0
  1.  
  2.  
  3. #include <iostream>
  4. #include <cmath>
  5. #include <iomanip>
  6. using namespace std;
  7.  
  8. void showInfo()
  9. {
  10.    
  11.     cout << "Hi, Andrew! This should be my personal information for the lecturer to see, lol\n";
  12.    
  13. }
  14.  
  15. void Q1()
  16. {
  17.    
  18.     int EquationChoice;
  19.     double s,u,t,a;
  20.    
  21.     do
  22.     {
  23.         cout << "\nEquation of motion - SUAT\n"
  24.             << "1. Find s\n"
  25.             << "2. Find a\n"
  26.             << "3. Return to main menu\n"
  27.             << "Option: ";
  28.         cin >> EquationChoice;
  29.         switch (EquationChoice)
  30.         {
  31.         case 1:
  32.             cout <<"Input the vale of u: ";
  33.             cin >> u;
  34.             cout <<"Input the vale of t: ";
  35.             cin >> t;
  36.             cout <<"Input the vale of a: ";
  37.             cin >> a;
  38.             s = u*t+ 0.5*a*t*t;
  39.             cout << "The value of s is " << fixed << setprecision(3) << s << " units\n";
  40.             break;
  41.         case 2:
  42.             cout <<"Input the vale of u: ";
  43.             cin >> u;
  44.             cout <<"Input the vale of t: ";
  45.             cin >> t;
  46.             cout <<"Input the vale of s: ";
  47.             cin >> s;
  48.             a = (2*(s-u*t))/(t*t);
  49.             cout << "The value of a is " << fixed << setprecision(3) << a << " units\n";
  50.             break;
  51.         case 3:
  52.             cout << "Goodbye!!";
  53.             break;
  54.         default:
  55.             cout <<"Please enter choice 1 - 3 only.\n";
  56.         }
  57.     }while (EquationChoice!=3);
  58. }
  59.  
  60. void Q2()
  61. {
  62.     int number, SmallestEven=0, LargestOdd=0;
  63.    
  64.    
  65.     do{
  66.         cout << "Please input an integer: ";
  67.         cin >>number;
  68.     if (SmallestEven==0 || LargestOdd ==0)
  69.     {
  70.         if (number%2 ==0)
  71.             SmallestEven=number;
  72.         else
  73.             LargestOdd=number;
  74.     }
  75.     else
  76.     {
  77.         if (number%2 ==0){
  78.             if(number<SmallestEven && number>0)
  79.                 SmallestEven=number;}
  80.         else{
  81.             if(number>LargestOdd)
  82.                 LargestOdd=number;}
  83.     }
  84.     }while(number>0);
  85.    
  86.     cout << "The smallest even number of all your input integers is " << SmallestEven << endl;
  87.     cout << "The largest odd number of all your input integers is " << LargestOdd << endl;
  88.    
  89.     cout << "\nMultiples:\n";
  90.    
  91.     int i,j,k;
  92.     for(i=0;i<=40;i+=10){
  93.         for(j=1;j<=10;j++){
  94.             cout << setw(3) << right << i+j;
  95.             if((i+j)%10==0)
  96.                 cout << endl;}
  97.         for(k=1;k<=10;k++){
  98.             if ((k+i)%SmallestEven==0 && (k+i)%LargestOdd==0)
  99.             {
  100.                 cout << setw(3) << right << "&";
  101.             }
  102.             else if ((k+i)%SmallestEven==0)
  103.                 cout << setw(3) << right << "B";
  104.             else if ((k+i)%LargestOdd==0)
  105.                 cout << setw(3) << right << "A";
  106.             else
  107.                 cout << setw(3) << right << " ";
  108.             if((i+k)%10==0)
  109.                 cout << endl << endl;
  110.         }
  111.     }
  112.    
  113. }
  114.  
  115. void Q3()
  116. {
  117.    
  118.        
  119.    
  120. }
  121.  
  122. int main(){
  123.     int prog_choice;
  124.    
  125.     showInfo();
  126.    
  127.     do {
  128.         cout << endl;
  129.         cout << "Assignment One - Program Selection Menu" << endl;
  130.         cout << "---------------------------------------" << endl;
  131.         cout << "Enter the program choice: ";
  132.         cin >> prog_choice;
  133.         switch (prog_choice){
  134.             case 1: Q1(); break;
  135.             case 2: Q2(); break;
  136.             case 3: Q3(); break;
  137.             case 4: break;
  138.             default:
  139.                 cout << "Please enter option 1 - 4 only." << endl;
  140.                 break;
  141.         }  
  142.     } while (prog_choice != 4);
  143.    
  144.     cout << "Program terminates. Good bye!" << endl;
  145.     return 0;
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement