0% found this document useful (0 votes)
67 views

Computer Programming Lab #04

This document is a lab journal submission for a computer programming course. It details three programming tasks completed by the student: [1] A program using nested if/else statements to determine a student's grade based on their marks; [2] A program using a switch statement to perform basic arithmetic operations; [3] A program using a switch statement to display different colors. The objectives of the lab were to learn how to use if/else nested statements and switch statements in C++ programs. Tools used included Visual Studio.
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)
67 views

Computer Programming Lab #04

This document is a lab journal submission for a computer programming course. It details three programming tasks completed by the student: [1] A program using nested if/else statements to determine a student's grade based on their marks; [2] A program using a switch statement to perform basic arithmetic operations; [3] A program using a switch statement to display different colors. The objectives of the lab were to learn how to use if/else nested statements and switch statements in C++ programs. Tools used included Visual Studio.
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/ 5

COMPUTER

PROGRAMMING LAB
CSC 113

BSE 1

FALL 2020
LAB JOURNAL#4

Submitted by: Muhammad


Ezaan Ali

Submitted To: Engr.


Waleed

Department of Software Engineering


Bahria University Islamabad Campus
Objectives:
Learning use of if else nested statement, and switch statement.

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;

if (marks >= 0 && marks <= 100)


{
cout << "Valid input\n";

if (marks >= 90)


cout << "Grade A"<<endl;
else if (marks < 90 && marks >= 70)
cout << "Grade B"<<endl;
else if (marks < 70 && marks >= 50)
cout << "Grade C"<<endl;
else if (marks>50)
cout << "Grade F"<<endl;
}
system("pause");
return 0;
}
Output

Task 2
• Write a program to perform simple arithmetic operations by using switch statement.
# include <iostream>

using namespace std;

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.

You might also like