You are on page 1of 5

PRACTICE TASK LAB 6

Question 1:
Write a Program to built a simple calculator using switch Statement
ANSWER:
#include<iostream>
using namespace std;
void main()
{
float a;
float b;
char num;
cout << "Enter the 1st number :" << endl;
cin >> a;
cout << "Enter the 2nd number :" << endl;
cin >> b;
cout << "press + for addition:" << endl;
cout << "press - for subtraction:" << endl;
cout << "press * for multipication:" << endl;
cout << "press / for division:" << endl;
cin >> num;
switch (num)
{
case '+':
cout << "Sum is:" << a+b<< endl;
break;
case '-':
cout << "Difference is:" <<a-b<< endl;
break;
case '*':
cout << "Multipication is:" <<a*b<< endl;
break;
case '/':
cout << "Division is:" <<a/b<< endl;
break;
}
}
Question 2:
Write a C++ program to print day of week name using switch case.
ANSWER:
#include<iostream>
using namespace std;
void main()
{

char num;
cout << "Enter the number of day:" << endl;
cin >> num;
switch (num)
{
case 1:
cout << "Monday" << endl;
break;
case 2:
cout << "Tuesday" << endl;
break;
case 3:
cout << "Wednesday" << endl;
break;
case 4:
cout << "Thursday" << endl;
break;
case 5:
cout << "Friday" << endl;
break;

case 6:
cout << "Saturday" << endl;

break;
case 7:
cout << "Sunday" << endl;
break;
default:
cout << "invalid input"<< endl;
}
}
Question 3:
Write a C++ program to check whether an alphabet is vowel or consonant using switch case.
ANSWER:
#include<iostream>
using namespace std;
void main()
{
char alphabet;
cout << "Enter the alphabet :" << endl;
cin >> alphabet;
switch (alphabet)
{
case 'a':
cout << "Alphabet is Vowel:" << endl;
break;
case 'e':
cout << "Alphabet is Vowel:" << endl;
break;
case 'i':
cout << "Alphabet is Vowel:" << endl;
break;
case 'o':
cout << "Alphabet is Vowel:" << endl;
break;
case 'u':
cout << "Alphabet is Vowel:" << endl;
break;
default:
cout << "Alphabet is consonant" << endl;
}
}
Question 5:
Write a Program to built a simple calculator using if else statements.

#include<iostream>
using namespace std;
void main()
{
float a;
float b;
char num;
cout << "Enter the 1st number :" << endl;
cin >> a;
cout << "Enter the 2nd number :" << endl;
cin >> b;
cout << "press + for addition:" << endl;
cout << "press - for subtraction:" << endl;
cout << "press * for multipication:" << endl;
cout << "press / for division:" << endl;
cin >> num;
if
(num == '+')
{

cout << "Sum is:" << a + b << endl;


}
else if (num == '-')
{
cout << "Difference is:" << a - b << endl;
}
else if (num == '*')
{
cout << "Multipication is:" << a*b << endl;
}
else if (num == '/')
{
cout << "Division is:" << a / b << endl;

}
}

You might also like