Cin A B Name
Cin A B Name
No 1 and 2 revision
Answer
11
2. Analyze the below program segment and find the syntax error.
int x,y,z;
float a = 5.0;
x = y = z = 10;
x = 9%2*3 + 54;
y = +2+z;
y = a/y + z%5;
if(y>z)
cout <<"\n value of y is greater than z";
else if(y<z)
cout <<"\n value of y is less than z";
else
cout <<"\n value of y and z are same";
value of y is less than z
Display “excellent” if mark is more than 90 and attendance is more than 80,
otherwise display “moderate”;
int number = 4;
float alpha = -1.0;
if (alpha < 0.0)
if (number > 0)
cout << "Here I am!" << endl;
else
cout << "No, I’m here!" << endl;
cout << "No, actually, I’m here!" << endl;
Here I am!
No, actually, I’m here!
int x=50;
int y=4;
if (x%y==0 || x%y==1) y++;
else if (x%y == 2)y--;
else y+=2;
cout << y << endl;
int x=50;
int y=4;
switch(x%y)
{
case 0:
case 1:
y++;
break;
case 2:
y--;
break;
default:
y+=2;
}
cout << y << endl;
case 2:
case 3:
cout<<”2 or 3”;
break;
Question 7 until 10 you have to create complete programs.
7. Clean Fast laundry shop is charging for the laundry based on a weight. Rate that imposed is
RM2.5 for one kilogram. If the total payment is RM30 and above, 10% discount would be
given to the customer every day except for the weekend (Sunday).
a. Write a pseudocode.
Start
input weight, status
total_price = weight*2.5
if (total_price >= 30 && status == 'y')
actual_price = total_price * 0.9;
discount = total_price - actual_price;
print total_price, discount and actual_price
End
#include <iostream.h>
void main()
{
8. ABC Fast laundry shop is charging for the laundry based on a type of material. Price rate that
imposed for one kilogram of each type are as follows :
Type Price
clothes RM 15 for 1 kilogram
blankets / towels RM 6 for 1 kilogram
comforter RM 10 for 1 kilogram
You may use if else if statement or switch statement to create a program.
#include <iostream.h>
void main()
{
char type;
float weight, price=0;
cout<<"Enter the type of material : ";
cin>>type;
cout<<"Enter the weight of the material : ";
cin>>weight;
switch (type)
{
case 'C':
price = weight * 15;
break;
case 'B':
case 'T':
price = weight * 6;
break;
case 'F':
price = weight * 10;
break;
default:
cout<<"invalid type \n";
}
cout<<"price = "<<price;
}
Calculate the price that the customer should pay after taking into account the discount
given.
#include <iostream.h>
void main()
{
float total_price;
float price_to_pay;
10 Shamira Laundry has designed a new calculation system for their shop. The price for each
type is as follows:
Type Price
Clothes RM 15 for 1 kilogram
blankets / towels RM 6 for 1 kilogram
comforter RM 10 for 1 kilogram
Only one type can be washed at a time. This laundry shop also provides discounts to its
customers as follow:
Calculate the price that the customer should pay after taking into account the discount
given. Display the output as below:
#include <iostream.h>
void main()
{
char type;
int customerNo;
float weight, price=0;
float price_to_pay;
switch (type)
{
case 'C':
price = weight * 15;
break;
case 'B':
case 'T':
price = weight * 6;
break;
case 'F':
price = weight * 10;
break;
default:
cout<<"invalid type \n";
}
cout<<"\n++++++++++++++++++++++++++++++++++++++++++++"<<endl;