Page 62 - PowerPoint Presentation
P. 62

CAVITE STATE UNIVERSITY
                               T3 CAMPUS
                               Department of Information Technology      DCIT 25 – Data Structures and Algorithms

               QUIZ 1: Data Structures and Algorithms: Analysis of a simple C++ program.
               Instruction: Analyze the given program and write the correct algorithm of it.

                  #include <iostream>
                 using namespace std;

                  int main() {

                        int num1, num2;
                        char choice;

                        cout << ”Enter First Number: “;
                        cin >> num1;

                        cout << “Enter Second Number: “;
                        cin >> num2;
                        cout << “What operation do you want to use?”;
                        cin >> choice;

                 switch(choice) {
                        case ‘+’ :
                               cout << “Your choice is addition, the answer is: “ << num1 + num2 ;
                        break;

                        case ‘-’ :

                               cout << “Your choice is subtraction, the answer is: “ << num1 - num2 ;
                        break;

                        case ‘*’ :
                               cout << “Your choice is multiplication, the answer is: “ << num1 * num2 ;
                        break;

                        case ‘/’ :
                               cout << “Your choice is division, the answer is: “ << num1 / num2 ;
                        break;

                        default:  cout << “Invalid Input!” ;

                        break;
                        }

                 return 0;
                 }


















                                                                                                  Page | 9
   57   58   59   60   61   62   63   64   65   66   67