You are on page 1of 5

INSTITUTE OF SPACE TECHNOLOGY

ISLAMABAD

Programming language lab


Electrical Engineering Department
Batch-19 Section-B
Lab No 1

Submitted To:
Sir Adnan Zafar
Submitted By:
M Saad Javed
Registration No:
200401013
Task # 1
Write a program in C++ to find the grade of a student. You must enter marks of five subjects and then
calculate the average marks (out of 100) and then apply the following grading criteria.
grade >= 90 Grade A
grade >= 80 Grade B
grade >= 70 Grade C
grade >= 60 Grade D

Pseudocode:
1: Begin
2: Initialize subject math, physics, chemistry, biology and psychology
3: Then ask user to input his marks of these subjects one by one.
4: Take average of the marks that user has input (sum the marks of five subjects then divide by
five)
5: Use nested if else condition to print grades if the average marks greater then 90 then print A
grade and if greater then 80 and less then 90 print B grade and if greater then 70 but less then 80
print C grade and if greater then 60 but less then 70 print D grade and if less than that print F.
6: End

Code:
//M Saad Javed//
//Reg no.200401013//
#include<iostream>
using namespace std;
int main() //defining main function
{
int math, physics, chemistry, biology, psychology, total; //initializing marks
cout << "Enter your marks in Math : " << endl; //asking user to input his marks
cin >> math ; //user will input his marks
cout << "Enter your marks in Physics : " << endl; //2nd object marks
cin >> physics;
cout << "Enter your marks in Chemistry : " << endl; //3rd object marks
cin >> chemistry;
cout << "Enter your marks in Biology : " << endl; //4th object marks
cin >> biology;
cout << "Enter your marks in Psychology : " << endl; //5th object marks
cin >> psychology;
total = (math + physics + chemistry + biology + psychology) / 5; //Calculating
average marks
if (total >= 90) //using if statement on the marks user will input
{
cout << "You have A grade" << endl; //output A if marks greater then 90
}
else if (total >= 80 && total < 90) //using else if statement if marks are not
grater then 90 then this will work
{
cout << "You have B grade" << endl;
}
else if (total >= 70 && total < 80) //again else if statement if previous one
is not correct
{
cout << "You have C grade" << endl;
}
else if (total >= 60 && total < 70) //again
{
cout << "You have D grade" << endl;
}
else if (total < 60) //marks lower then 60 then out put F
{
cout << "You have F grade" << endl;
}
}

Output:

Link:
https://repl.it/@SaadJaved/Task-No-1
Task # 2
Write a Program in C++ that takes an integer values from the user in an array of 5. First display
the array, show the sum of the array, and then tell whether the sum of the array is EVEN or
ODD using switch case.

Pseudocode:
1: Begin
2: Initialize an array that can have five elements
3: Initialize integer variable s and sum the value of sum will start from 0.
4: Ask user to input array values one by one using for loop.
5: Using second for loop display values that user entered in array.
6: Using third for loop find the sum of values user entered in array.
7: Using switch statement if sum divided by 2 gives reminder 0 then the sum is even otherwise the
sum is odd number.
8: End

Code:
//M Saad Javed//
//Reg No. 200401013//
#include<iostream>
using namespace std;
int main() //defining main function
{
int ist[5];
int s, sum=0;
cout << "Please enter elements for array : \n";
for (s = 0; s < 5; ++s) //for loop for entering values in array
cin >> ist[s];
cout << "Entered values : " << endl;
for (s = 0; s < 5; s++) //for loop for displaying value that has been entered
cout << ist[s] << endl;
for (s = 0; s < 5; s++) //for loop for calculating sum of values
{
sum = sum + ist[s]; //adding values of array
}
cout << "Sum : " << sum << endl;
switch (sum % 2) //this will return either 0 or 1
{
case 0: //if modulus is zero
cout << sum << " is even number" << endl;
break; //end switch statement
case 1: //if modulus is one
cout << sum << " is odd number" << endl;
}
}

Output:

Link:
https://repl.it/@SaadJaved/Task-No-2

You might also like