Task #1: Code

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Task #1:

Code
#include <iostream>
using namespace std;
void main()
{
int month;
cout << "Enter the month";
cin >> month;
switch (month)
{
case 1: case 3: case 5: case 7: case 8: case 10: case 12:
cout << "This month has 31 days.";
break;
case 2:
cout << "This month has 28 days.";
break;
case 4: case 6: case 9: case 11:
cout << "This month has 30 days.";
break;

default:
cout << "Invalid";
}
}

Output

Question 2
Code
#include <iostream>
using namespace std;
void main()
{
char alphabet;
cout << "Enter a alphabet:";
cin >> alphabet;
switch (alphabet)
{
case 'a': case 'e': case 'i': case 'o': case 'u':
cout << "This alphabet is a vowel";
break;

default:
cout << "This alphabet is consonent.";
}
}

Output

Question 3
#include <iostream>
using namespace std;
void main()
{
float a, b;
char k;
cout << "Enter First Number:";
cin >> a;
cout << "Enter Second Number:";
cin >> b;
cout << "Which Function you want to perform:";
cin >> k;
switch (k)
{
case '+':
cout << "The Sum of Numbers is:";
cout << a+ b;
break;
case '-':
cout << "The Difference of Numbers is:";
cout << a - b;
break;
case '*':
cout << "The Product of Numbers is:";
cout << a * b;
break;
case '/':
cout << "The Division of Numbers is:";
cout << a / b;
break;

default:
cout << "Invalid command";
}
}
Output

Question 4
Code
#include <iostream>
using namespace std;
void main()
{
char op ;
cout << "Enter the character:";
cin >> op ;
switch (op)
{
case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9:
case 10:
cout << "This is a digit.";
break;
case 'a': case 'w': case 'i': case 's':
cout << "This is a alphabet.";
break;
case '+': case '-': case '*': case '/':
cout << "This is a special character";
break;
default:
cout << "Invalid command";
}
}

Output

Question 5
Code
#include <iostream>
using namespace std;
int main()
{
float Physics,Chemistry,Maths,Computer,Biology ;
cout << "Enter your marks in Physics:";
cin >> Physics ;
cout << "Enter your marks in Chemistry:";
cin >> Chemistry;
cout << "Enter your marks in Maths:";
cin >> Maths;
cout << "Enter your marks in Computer:";
cin >> Computer;
cout << "Enter your marks in Biology:";
cin >> Biology;
float ObtainedMarks = Physics + Chemistry + Maths + Computer + Biology;
float Percentage = (ObtainedMarks / 500) * 100;
char grade;
switch (int (Percentage)/10)
{
case 9:
grade = 'A';
break;
case 8:
grade = 'B';
break;
case 7:
grade = 'C';
break;
case 6:
grade = 'D';
break;
case 5: case 4:
grade = 'E';
break;
default:
grade = 'F';
}
cout << "Percentage"<<Percentage<<"%"<<endl;
cout << "Your grade is:";
cout << grade;
return 0;

Output

Question 6
Code
#include<iostream>
using namespace std;
void main()
{
int c,s;
cout << "Enter Cost Price:";
cin >> c;
cout << "Enter Selling Price:";
cin >> s;
switch (c > s)
{
case true:
cout << "Loss";
case false:
cout << "Profit";
break;
}

Output

You might also like