Computer Programming Lab #04
Computer Programming Lab #04
PROGRAMMING LAB
CSC 113
BSE 1
FALL 2020
LAB JOURNAL#4
Tools used
Visual studio
Task # 1
Write a program in C++ to input marks obtained by a student in a subject. The total marks are
100. Find out the grade of the student by using the if-else nested structure. The grade is:
• If marks are equal to or greater than 90, grade is A
• If marks are equal to or greater than 70 and less than 90, grade is B
• If marks are equal to or greater than 50 and less than 70, grade is C
• If marks are less than 50, grade is “F”.
# include <iostream>
using namespace std;
int main()
{
int marks;
cout << "Entered marks: ";
cin >> marks;
Task 2
• Write a program to perform simple arithmetic operations by using switch statement.
# include <iostream>
int main()
{
char op;
float num1, num2;
cout << "Enter operator either + or - or * or /: ";
cin >> op;
cout << "Enter first number ";
cin >> num1;
cout << "Enter second number";
cin >> num2;
switch (op)
{
case '+':
cout << num1 + num2;
break;
case '-':
cout << num1 - num2;
break;
case '*':
cout << num1*num2;
break;
case '/':
cout << num1 / num2;
break;
default:
cout << "incorrect operator";
break;
}
system("pause");
return 0;
}
output
Task 3:
• Write a program to display different colors by using switch statement.
Output
conclusion
learnt use of switch and nested if else statement.