[cpp] Tutorial 3 Solutions
Viewer
- //Exercise 1
- #include <iostream>
- using namespace std;;
- int main()
- {
- const int min_height = 48;
- int height = 60;
- bool pregnant = true;
- if(height < min_height || pregnant){
- std::cout<<"Sorry"<<endl;
- }else{
- std::cout<<"Okay! have fun"<<endl;
- }
- return 0;
- }
- //Exercise 2
- #include <iostream>
- using namespace std;;
- int main()
- {
- int x = 60;
- int y = 55;
- int z = 63;
- int max;
- if((x >= y) && (x >= z))
- max = x;
- else if ((y >= x) && (y >= z))
- max = y;
- else
- max = z;
- std::cout<<"Maximum integer is ";
- std::cout<< max << endl;
- return 0;
- }
- //Exercise 3
- #include <iostream>
- using namespace std;;
- int main()
- {
- const int TRUE = 1;
- const int FALSE = 0;
- int honors; // true if the student is an honors student
- int awards; // true if the student has won an academic award
- int good_student; // true under certain circumstances...
- if (honors == TRUE && awards == TRUE) {
- good_student = TRUE;
- }else{
- good_student = FALSE;
- }
- return 0;
- }
- //Excercise 4
- 'c' - "Medium Low"
- 'x' - "Off the Scale"
- 'D' - "Low"
- //Exercise 5
- #include <iostream>
- using namespace std;;
- int main()
- {
- double first_num;
- double second_num;
- int attempts = 0;
- double result;
- char code;
- do {
- cout << "Enter first number" << endl;
- cin >> first_num;
- cout << "Enter second number" << endl;
- cin >> second_num;
- cout << "Enter code of operation" << endl;
- cin >> code;
- switch (code) {
- case '+' :
- result = first_num + second_num;
- cout << "Final result = " ;
- cout << result <<endl;
- break;
- case '-' :
- result = second_num - first_num;
- cout << "Final result = ";
- cout << result <<endl;
- break;
- case '*' :
- result = first_num * second_num;
- cout << "Final result = ";
- cout << result <<endl;
- break;
- case '/' :
- result = second_num / first_num;
- cout << "Final result = ";
- cout << result <<endl;
- break;
- default :
- attempts++;
- cout << "Please re-enter operation" << endl;
- }
- } while(attempts < 3);
- cout << "The code was not entered properly, the program has to terminate" << endl;
- return 0;
- }
- //Exercise 6
- output = "Cool is all we got"
Editor
You can edit this paste and save as new:
File Description
- Tutorial 3 Solutions
- Paste Code
- 27 Jan-2021
- 2.86 Kb
You can Share it: