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