Tutorial 2 Qs
Tutorial 2 Qs
Tutorial 2 Qs
1 2011/2012
Tutorial 2
Tutorial 2
Program 3:
#include <iostream> using namespace std; int main() { int x, y, z; x = y = z = 0; x +=2; y -= 1; z *= 3; cout << x << << y << << z << endl; system ("Pause"); return 0; }
Tutorial 2
Q2: The following program has syntax mistakes. Correct them. On each successive line, assume that
Q3: Consider the following program segment. Complete it by following the instructions below.
#include <iostream> using namespace std; int main() { // variable declaration // executable statements return 0; }
1. Write C++ statements that declare the following variables: num1, num2, num3, and average of type int 2. Write C++ statements that store 125 into num1, 28 into num2, and -25 into num3. 3. Write C++ statements that stores the average of num1, num2, and num3, into average. 4. Write C++ statements that output the values of num1, num2, num3, and average.
Tutorial 2
Q4: Write a program that displays the following information, each on a separate line: a. Your name b. Your address, with city, state, and zip code. c. Your telephone number d. Your collage major Using only a single cout statement to display all of this information.
Extra Exercise 1. Newtons law states that the force, F, between two bodies of masses M1 and M2 is given by: M M F k 1 2 2 d In which k is the gravitational constant ( approximately 6.67 x 10-8 dyn. cm2/g2). Write a program that prompts the user to input the masses of the bodies and the distance between the bodies. The program then outputs the force between the bodies as shown below.
2. There are three seating categories at a stadium. For a football game. Class A seats cost RM 20, Class B seats cost RM 15, and Class C costs RM 9. Write a program that asks how many tickets for each class of seats were sold, then displays the amount of income generated from ticket sales. Format your dollar amount in a fixed-point notation with two decimal points and make sure the decimal point is always displayed.