10. If the variable divisor is not zero, divide the variable dividend by divisor, and
store the result in quotient. If divisor is zero, assign it to the quotient. Then print
all the variables. Assume the dividend and divisor are integer and quotient is a
double.
11. write a program that create the following number patern.
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3 1 2
1
12. Write a program that accepts student mark out of 100, and return the
corresponding letter grade based on the following condition:
if mark is greater than or equal to 90 A
if mark is greater than or equal to 80 and less than 90 B
if mark is greater than or equal to60 and less than 80 C
if mark is greater than or equal to 40 and less than 60 D
if mark is less than 40 F
for other cases NG
N.B write the program using both switch and else-if
#include<iostream>
using namespace std;
int main()
{
int divid;
int divis;
double quotient;
cout << "1)Division program:\n";
cout << "Please, enter divident: ";
cin >> divid;
cout << "Please, enter divisor: ";
cin >> divis;
if (divis != 0)
quotient = (double)divid / divis;
else
quotient = 0;
cout << "Divident: " << divid;
cout << "\nDivisor: " << divis;
cout << "\nQuotient: " << quotient;
cout << "\n2)Pattern program:\n";
int j = 0;
while (j<=7)
{
for (int i = 1; i <= 9-j; i++)
{
cout << i<<" ";
if (j == 7)
i++;
}
if (j == 6)
{
for (int i = 1; i <= 2; i++)
{
cout << i << " ";
}
}
cout << endl;
j++;
}
cout << "\n3)Student mark program:\n";
int grade;
cout << "Please, enter a grade of student: ";
cin >> grade;
char ch;
if (grade <= 100&&grade >= 90)
ch = 'A';
else if (grade >= 80 && grade < 90)
ch = 'B';
else if (grade >= 60 && grade < 80)
ch = 'C';
else if (grade >= 40 && grade < 60)
ch = 'D';
else if (grade >= 0&&grade < 40)
ch = 'F';
else
ch = '0';
cout << endl;
switch (ch)
{
case 'A':
{
cout << "A";
break;
}
case 'B':
{
cout << "B";
break;
}
case 'C':
{
cout << "C";
break;
}
case 'D':
{
cout << "D";
break;
}
case 'F':
{
cout << "F";
break;
}
case '0':
{
cout << "NG";
break;
}
}
}
Comments
Leave a comment