COS1511-ASSIGNMENT-2.rtf - Name Ramanugu Rolivhuwa Student...

Info icon This preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Name: Ramanugu Rolivhuwa Student No: 55333427 Module: COS1511 Unique No: 745328 Due Date: 9 April 2018 QUESTION 1 1a. #include <iostream> #include <iomanip> using namespace std; int main() { // Fill in the code to define an integer variable called selection int selection ; cout << "Please enter the choice of Hotdog " << "(a number from 1 to 4 or 0 to quit) " << endl; cout << "Hot Dog Menu " << endl << endl; cout << "1: Plain hotdog " << endl; cout << "2: Chilli hotdog " << endl; cout << "3: Cheese hotdog " << endl; cout << "4: Russian hotdog " << endl; cout << "0: QUIT " << endl <<endl << endl; cin >> selection ; while (selection > 4 ) //complete the condition { cout << "Invalid choice , Please re-enter : "; cin >> selection; cout<< endl; } cout << "You have selected option number : " << selection << endl; return 0; }
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
1b. #include <iostream> #include <iomanip> using namespace std; int main() { int selection , number ; float cost ; cin >> selection ; cout << "You have selected option number " << beverage <<endl; cout << "How many hotdogs would you like?" << endl; // Fill in the code to read in number cin >> number ; // Fill in the code to begin a switch statement // that is controlled by selection switch(selection) { case 1: cost = number * 15.0; cout << "The total cost is R " << cost << endl; break; // Fill in the code for the case chilli hotdog ( R12.50 each) case 2: cost = number * 12.50; cout << "The total cost is R " << cost << endl; break; // Fill in the code for the case chesse hotdog (R17.00 each) case 3: cost = number * 17.0; cout << "The total cost is R " << cost << endl; break; // Fill in the code for the case Russian hotdog (R22.50 each) case 4: cost = number * 22.50; cout << "The total cost is R " << cost << endl; break; case 0: cout << " Please come again" << endl;
Image of page 2
break; default: cout << "Invalid selection"; cout << " Try again please" << endl; } return 0; } QUESTION 2 2a. #include <iostream> #include <iomanip> using namespace std; int main() { int i = 1; while( i <= 10) { if (i < 5 && i != 2) cout << 'X'; i++ ; } return 0; } 2b. The output of this program is 19 The variable “sum” must be assigned to ‘0’ instead of ‘ 1 ‘ , sum = 0 . “next++ “ must be written under “ sum = sum + next ” inside the while loop . #include <iostream> #include <iomanip> using namespace std; int main()
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
{ int next = 2, sum = 0; while (next <= 5) { sum = sum + next; next++; } cout << "The sum of 2 through 5 is " << sum << endl; return 0; } QUESTION 3 3a. #include <iostream> using namespace std; int main() { int numStudents; int n ; float numHours, total, average; int student,day = 0; // these are the counters for the loops cout << "This program will find the average number of hours a day" << " that a student spent programming over a long weekend\n\n"; cout << "How many students are there?" << endl << endl; cin >> numStudents; cout << "How many days are there?" << endl << endl; cin >> n; for( student = 1; student <= numStudents; student++) { total = 0; for(day = 1; day <= n; day++) { cout << "Please enter the number of hours worked by student"<< student <<" on day " << day << "." << endl; cin >> numHours; total = total + numHours; } average = total / n ; cout << endl; cout << "The average number of hours per day spent programming " << "by student " << student << " is " << average << endl << endl << endl; } return 0;
Image of page 4
} 3b.
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern