Академический Документы
Профессиональный Документы
Культура Документы
1) Trace all errors in Program 2. Then, briefly explain the function of header file <iomanip>
1 //Program 2
2 #include <iostem>
3 #include <iomanip>
4 using namespace std;
5 int main()
6 {
7 double num1, num2 total;
8 num1 = 3;
9 num2 = 1.32;
10 total = num1 + num2
11 cout >> “Total : ”;
12 cout << setprecision(2) << total;
13 system(“PAUSE”);
14 return 0;
15 }
// Program 3
double age=-1, ticket;
while (age<0)
{ cout<<”Enter the age: “;
cin>>age;
}
if (age>=0 && age<=3)
ticket = 0;
else if (age>3 && age<=12)
ticket = 5;
else
{ if (age<55)
ticket = 14;
else
ticket = 7;
}
cout<<”\nThe ticket price for age ”
<<age<< “ is RM” <<ticket<<endl;
a) Find the expected output for the following age;
i. -2
ii. 3.5
iii. 55
iv. 14
b) If data type for variable age is change into int, what is the expected output for age 12.9?
3. Convert the nested loop for in Program 4 to while loop for inner and outer loops.
//Program 4
int jumlah=100,i,j;
for( i=2; i<12; i+=2)
{
int kira = 0;
for( j=1; j<=5; j++)
{
kira+=2;
jumlah-=2;
}
cout<< kira <<endl;
}
cout<< jumlah <<endl;
4. Fill in the blanks and trace the output if input is 12.15.
1 //Program 6
2 #include <iostream>
3 #include <iomanip.h>
4 #define TAX 0.06
5 using namespace std;
7 ______________________ //(2)
8 {
9 double price, taxAddition, total;
10 taxAddition = 0;
11 cout << "Please insert price for the item : RM ";
12 cin >> price;
1 // Program 7
2 #include “iostream.h”
3 #include “iomanip.h”
4 int main()
5 {
6 for (int x=0; x<35; x+=7)
7 {
8 cout<<'\t'<<x;
9 }}
10 return 0;
a) 11Determine
} the purpose of the program.
b) Identify the output of the program.
c) Convert the program to while loop.
Table 1 below shows a list of message to be displayed for withdrawal process at ATM machine.
Draw a flowchart and write two C++ program (using both switch case and if else statement)
that will read in the requested amount, display the message based on the amount and display
amount if the request accepted. Your program should implement the do while loops and decision
statements to re-produce the required outputs.
Question 8
Draw a flowchart and write two C++ program (using both switch case and if else statement)
to execute the basic calculation such as addition (+), minus (-), multiplication (*) and divide (/).
User needs to input two integers and select one of the basic calculations. Write the full program
based on sample output as below. Your program should implement the do while loops and decision
statements to re-produce the required outputs.