0% found this document useful (0 votes)
17 views9 pages

Lab6 (PF)

The document contains a series of C++ programming tasks that demonstrate the use of switch statements, user input, and basic arithmetic operations. Each task includes code snippets for handling different scenarios such as determining the day of the week, performing arithmetic operations, checking for vowels, and evaluating grades with grace marks. The code is structured to prompt user input and provide corresponding outputs based on the conditions set in the switch cases.

Uploaded by

Ninja TitanMoxie
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views9 pages

Lab6 (PF)

The document contains a series of C++ programming tasks that demonstrate the use of switch statements, user input, and basic arithmetic operations. Each task includes code snippets for handling different scenarios such as determining the day of the week, performing arithmetic operations, checking for vowels, and evaluating grades with grace marks. The code is structured to prompt user input and provide corresponding outputs based on the conditions set in the switch cases.

Uploaded by

Ninja TitanMoxie
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

LAB 6

Task 1:
#include <iostream>
using namespace std;

int main()
{
int day;
cout << "Enter day: ";
cin >> day;
switch (day)
{
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;
}
system("pause");
return 0;
}
Task 2:
#include <iostream>
using namespace std;
int main()
{
int day = 4;
switch (day)
{
case 6:
cout << "Today is Saturday";
break;
case 7:
cout << "Today is Sunday";
break;
default:
cout << "Looking forward to the weekend" << endl;
}
system("pause");
return 0;
}
Task 3:
#include <iostream>
using namespace std;

int main()
{
int num1, num2;
cout << "Enter the value of the first number: ";
cin >> num1;
cout << "Enter the value of the second number: ";
cin >> num2;

char operation;
cout << endl;
cout << "Press + for sum" << endl;
cout << "Press - for subtraction" << endl;
cout << "Press * for multiplication" << endl;
cout << "Press / for division" << endl
<< endl;

cout << "Enter your number for operation: ";


cin >> operation;
cout << endl;
if (operation == '+')
{
cout << "The sum result is " << num1 + num2 << endl;
}
else if (operation == '-')
{
cout << "The subtraction result is " << num1 - num2 << endl;
}
else if (operation == '*')
{
cout << "The multiplication result is " << num1 * num2 << endl;
}
else if (operation == '/')
{
cout << "The divison result is " << num1 / num2 << endl;
}
else
{
cout << "Invalid input for operation" << endl;
}
system("pause");
return 0;
}

Task 4:
#include <iostream>
using namespace std;

int main()
{

char alphabet;
cout << "Enter your alphabet: " << endl;
cin >> alphabet;

if (alphabet >= 'A' && alphabet <= 'Z')


{
alphabet = alphabet + 32;
}
switch (alphabet)
{
case 'a':
cout << "This letter is a vowel" << endl;
break;
case 'e':
cout << "This letter is a vowel" << endl;
break;
case 'i':
cout << "This letter is a vowel" << endl;
break;
case 'o':
cout << "This letter is a vowel" << endl;
break;
case 'u':
cout << "This letter is a vowel" << endl;
break;
default:
cout << "This letter is not a vowel" << endl;
}

system("pause");
return 0;
}

Task 5:
#include <iostream>
using namespace std;

int main()
{

char alphabet;
cout << "Enter your alphabet: " << endl;
cin >> alphabet;

if (alphabet >= 'A' && alphabet <= 'Z')


{
alphabet = alphabet + 32;
}
switch (alphabet)
{
case 'a':
cout << "This letter is a vowel" << endl;
break;
case 'e':
cout << "This letter is a vowel" << endl;
break;
case 'i':
cout << "This letter is a vowel" << endl;
break;
case 'o':
cout << "This letter is a vowel" << endl;
break;
case 'u':
cout << "This letter is a vowel" << endl;
break;
default:
cout << "This letter is not a vowel" << endl;
}
return 0;
}

Task 6:
#include <iostream>
using namespace std;

int main()
{
int num;
cout << "Enter an integer: " << endl;
cin >> num;
switch ((num > 0) - (num < 0))
{
case 1:
cout << "The number is Positive" << endl;
break;
case -1:
cout << "The number is Negative" << endl;
break;
default:
cout << "The number is Zero" << endl;
break;
}

system("pause");
return 0;
}

Task 7:
#include <iostream>
using namespace std;

int main()
{
char grade;
int failed_subjects;

cout << "Enter your grade(A, B, or C): " << endl;


cin >> grade;
cout << "Enter number of your failed subjects: " << endl;
cin >> failed_subjects;

switch (grade)
{

case 'A':
case 'a':

if (failed_subjects <= 3)
{
cout << "The total grace marks are: " << 5 * failed_subjects << endl;
}
else
cout << "No grace marks are awarded" << endl;
break;

case 'B':
case 'b':

if (failed_subjects <= 2)
{
cout << "The total grace marks are: " << 4 * failed_subjects << endl;
}
else
cout << "No grace marks are awarded" << endl;
break;

case 'C':
case 'c':

if (failed_subjects == 1)
{
cout << "The total grace marks are: " << 5 * failed_subjects << endl;
}
else
cout << "No grace marks are awarded" << endl;
break;

default:
cout << "The grade is invalid " << endl;
}
system("pause");
return 0;
}
S

You might also like