You are on page 1of 13

Task 1

#include<iostream>
using namespace std;
int main()
{
int student_marks;
cout << "Grade A = 80 to 90 marks" << endl;
cout << "Grade B = 60 to 70 marks" << endl;
cout << "Grade C = 50 to 60 marks" << endl;
cout << "Please enter marks of the student" << endl;
cin >> student_marks;

switch (student_marks)
{
case 90 : cout << "Your grade is A" << endl;
break;

case 65: cout << "Your grade is B" << endl;


break;

case 50: cout << "your grade is C" << endl;


break;

default: cout << "You did not enter a valid number" << endl;
break;
}

Output

Task 2

#include<iostream>
using namespace std;
int main()
{
int apple, mangoes, oranges, apple_rate, mango_rate, orange_rate,Total;
apple = 100;
mangoes = 140;
oranges = 120;
cout << "Enter number of apples you want to buy: " << endl;
cin >> apple;
cout << "Enter number of mangoes you want to buy:" << endl;
cin >> mangoes;
cout << "Enter number of oranges you want to buy:" << endl;
cin >> oranges;
apple_rate = apple * 100;
mango_rate = mangoes * 140;

cout << "Total price of apples= " << apple_rate << endl;
cout << "Total price of mangoes= " << mango_rate << endl;

if (oranges > 12)


{
orange_rate = (oranges*120)*0.8 ;
cout << "Total price of oranges" << orange_rate << endl;

}
else
{
orange_rate = oranges * 120;
cout << "Total price of oranges= " <<orange_rate<< endl;
}
Total = orange_rate + apple_rate + mango_rate;
cout << "Total = " <<Total<< endl;
}

Output

Task 3

// Task 3: Write a program that displays 1-20 using 'for' loop.

#include<iostream>
using namespace std;

int main()
{

cout << "Program that displays number from 1-20: " << endl;

for (int i = 1; i <= 20; ++i) {


cout << i << endl;
}
return 0;

Output

Task 4

// Task 4: Write a program that displays 20-1 using 'for' loop.

#include<iostream>
using namespace std;

int main()
{

cout << "Program that displays number from 20-1: " << endl;

for (int i = 20; i >= 1; --i) {


cout << i << endl;
}
return 0;

Output
Task 5

// Task 5: Write a program to display the multiplication table for 5*10.

#include<iostream>
using namespace std;

int main()
{

cout << "Multiplication table for 5*10: " << endl;

for (int i=1; i <= 10; ++i) {


cout << i*5 << endl;
}
return 0;

Output
Task 6

// Task 6: Write a program to get a number from the user and display (check whether)
number is EVEN or ODD. Press 999 to exit.

#include<iostream>
using namespace std;

int main()
{
int a;
cout << "Enter any number" << endl;
cin >> a;

if (a == 999) {
cout << "Exit" << endl;
}
else {
if (a % 2 == 0) {
cout << "EVEN" << endl;
}
else {
cout << "ODD" << endl;
}
}
return 0;
}

Output

Task 7
// Task 7: Write a program to get a range of numbers from the user and display all EVEN
and ODD number from that range.

#include<iostream>
using namespace std;
int main()
{
int range;
cout << "Enter any range" << endl;
cin >> range;

for (int i = 1; i <=range; ++i)

if (i % 2 == 0) {
cout << "EVEN " << i <<endl;
}
else {
cout << "ODD " << i <<endl;
}
return 0;
}

Output

Task 8

// Task 8: Write a program to print all prime numbers from 2 to N. N is to be taken from
the user.

#include<iostream>
using namespace std;
int main()
{
int N, a;
cout << "Enter any number: ";
cin >> N;

for (int i = 2; i <= N; ++i) {

for (a = 2; a <= (i / 2); ++a) {


if (i % a == 0) {
a = i;
break;
}
}
if (a != i) {
cout << i << " ";
}
}
return 0;
}

Output

Task 9

// Task 9: Design a program for your local seller Egg Ranch. The user will enter
thenumber of eggs gathered and the program will output the number of dozens as well as
the number of excess eggs. Continue this process until a negative number is entered.

#include<iostream>
using namespace std;

int main()
{
int eggs, dozen, excess;
cout << "Enter the number of eggs gathered: ";
cin >> eggs;

while (eggs >= 12 && eggs >= 1) {


dozen = eggs / 12;
excess = eggs % 12;
cout << "Number of dozens: " << dozen << endl;
cout << "Number of excess: " << excess << endl;

cout << "Enter the number of eggs gathered: ";


cin >> eggs;
}

return 0;
}

Output
Task 10

// Task 10: Write a program that calculates the price of an item for each of the five
days, given the original price.

#include<iostream>
using namespace std;

int main()
{
double Monday, Tuesday, Wednesday, Thursday, Friday;
int price;
char ch;
int x = 0;
double discount = 0.1;

cout << "Enter the price of the item: " << endl;
cin >> price;

Monday = price * 0.9;


Tuesday = Monday * 0.9;
Wednesday = Tuesday * 0.9;
Thursday = Wednesday * 0.9;
Friday = Thursday * 0.9;

do {
cout << "Choose the day on which you want to review the price of the item: \n1:
Monday \n2: Tuesday \n3: Wednesday \n4: Thursday \n5:Friday \n\n\nAt any point, if you
want to quit, press 0" << endl;
cin >> ch;

switch (ch) {
case '1':
cout << "The price of item on Monday is: " << Monday << endl;
break;
case '2':
cout << "The price of item on Tuesday is: " << Tuesday << endl;
break;

case '3':
cout << "The price of item on Wednesday is: " << Wednesday << endl;
break;
case '4':
cout << "The price of item on Thursday is: " << Thursday << endl;
break;
case '5':
cout << "The price of item on Friday is: " << Friday << endl;
break;
case '0':
return 0;
default:
cout << "Wrong Input. Try Again" << endl;
}
} while (x < 1);
}

Output

Task 11

#include<iostream>
using namespace std;
int main()
{
int Physics, Chemistry, Biology, Mathematics, Computer, percentage,
marks_obtained, total_marks;
cout << "Please enter marks of Physics: " << endl;
cin >> Physics;
cout << "Please enter marks of Chemistry: " << endl;
cin >> Chemistry;
cout << "Please enter marks of Biology: " << endl;
cin >> Biology;
cout << "Please enter marks of Mathematics" << endl;
cin >> Mathematics;
cout << "Please enter marks of Computer: " << endl;
cin >> Computer;

marks_obtained = Physics + Chemistry + Biology + Mathematics + Computer;


total_marks = 500;
percentage = 100 * marks_obtained / total_marks;

cout << "Marks obtained in all subjects: " << marks_obtained << endl;
cout << "Percentage: " << percentage << endl;

if(percentage >= 90) {


cout << "Your grade is A" << endl;
}
else if (percentage >= 80) {
cout << "Your grade is B" << endl;
}
else if (percentage >= 70) {
cout << "Your grade is C" << endl;
}
else if (percentage >= 60) {
cout << "Your grade is D" << endl;
}
else if (percentage >= 40) {
cout << "Your grade is E" << endl;
}
else if (percentage < 40) {
cout << "Your grade is F" << endl;
}
else {
cout << "You entered invalid number" << endl;
}
return 0;

Output

Task 12

#include<iostream>
using namespace std;
int main()
{
int balance, input1, input2;

cout << "Choose an account type : \n1 : Personal \n2 : Business" << endl;
cin >> input1;

if (input1 == 1) {
cout << "Choose account level: \n1: Standard \n2: Gold \n3: Gold+" << endl;
cin >> input2;

cout << "Enter balance: " << endl;


cin >> balance;

if (input2 == 1 && balance >= 0) {


cout << "Your interest rate is 1.2%" << endl;
}
else if (input2 == 1 && balance < 0) {
cout << "Rejected" << endl;
}
else if (input2 == 2 && balance >= 1000) {
cout << "Your interest rate is 1.9%" << endl;
}
else if (input2 == 2 && balance < 1000) {
cout << "Rejected" << endl;
}
else if (input2 == 3 && balance >= 5000) {
cout << "Your interest rate is 2.3%" << endl;
}
else if (input2 == 3 && balance < 5000) {
cout << "Rejected" << endl;
}

}
else if (input1 == 2) {
cout << "Choose account level: \n1: Standard \n2: Platinum" << endl;
cin >> input2;

cout << "Enter balance: " << endl;


cin >> balance;

if (input2 == 1 && balance >= 1500) {


cout << "Your interest rate is 1.7%" << endl;
}
else if (input2 == 1 && balance < 1500) {
cout << "Rejected" << endl;
}
else if (input2 == 2 && balance >= 10000) {
cout << "Your interest rate is 2.5%" << endl;
}
else if (input2 == 2 && balance < 10000) {
cout << "Rejected" << endl;
}

}
return 0;
}

Output

Task 13

#include<iostream>
using namespace std;

int main()
{
int noise_loudness;

cout << "Please enter loudness: ";


cin >> noise_loudness;

if (noise_loudness <= 50) {


cout << "Quiet" << endl;
}
else if (noise_loudness >= 51 && noise_loudness <= 70) {
cout << "Intrusive" << endl;
}
else if (noise_loudness >= 71 && noise_loudness <= 90) {
cout << "Annoying" << endl;
}
else if (noise_loudness >= 91 && noise_loudness <= 110) {
cout << "Very annoying" << endl;
}
else if (noise_loudness > 110) {
cout << "Uncomfortable" << endl;
}
return 0;
}

Output

You might also like