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

CS201P Assignment 1 Solution Fall 2024

Notes

Uploaded by

tasbihahussain23
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)
25 views

CS201P Assignment 1 Solution Fall 2024

Notes

Uploaded by

tasbihahussain23
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/ 6

GET MORE SOLUTIONS FILE FROM

VUAnswer.pk
CS201P ASSIGNMENT 1 SOLUTION FALL 2024

Due Date: 7-Nov-2024


Total Marks: 20

DO NOT COPY PASTE

FOR MORE CORRECT PAID SOLUTIONS CONTACT


WHATSAPP +923162965677

Assignment Submission Instructions

You must submit only a .cpp file on the assignments interface of CS201P from your LMS
account.

Remember that if you have not used your name and student id in the program your marks
will be deducted. Also, printf and scanf are not allowed.

Question Task

Develop a console-based application that allows students to input their marks for Any three
subjects. The application should calculate and display the obtained marks, average marks, grade,
highest marks, and lowest marks based on the entered values.

The program should:


1. Your student id and name must be displayed before the result ( No need to prompt
student id and name from the user, you can just hard-code it).
GET MORE SOLUTIONS FILE FROM
VUAnswer.pk
2. Prompt the user to enter marks for any three subjects, ensuring that the entered marks for
each subject do not exceed 100.
3. Compute the average of the entered marks.

4. Calculate the grade based on the average marks.


o Grade A: Average >= 90
o Grade B: Average >=80
o Grade C: Average >=70
o Grade D: Average >= 60
o Grade F: Average < 60
5. Identify the highest marks among the subjects.
6. Identify the lowest marks among the subjects.
7. Display the obtained marks.
8. Display the calculated results (average, grade, highest and lowest marks).
Requirements:
1. Use a while loop structure for repetitions like inputting multiple marks.
2. Use if else structure for decision. This will allow the program to determine the highest
and lowest marks entered, as well as to assign grades based on the calculated average.
3. Use const where appropriate to protect data that should not be modified.

Solution

CODE:
#include <iostream>
#include <algorithm>
using namespace std;
GET MORE SOLUTIONS FILE FROM
VUAnswer.pk

int main() {
const string studentID = "BC123456789";
const string studentName = "Sarim";

cout << "Student ID: " << studentID << endl;


cout << "Student Name: " << studentName << endl;
cout << endl;

int s1, s2, s3;


cout << "Enter marks for Subject 1: ";
while (true) {
cin >> s1;
if (s1 <= 100) break;
cout << "Marks cannot exceed 100. Please re-enter: ";
}

cout << "Enter marks for Subject 2: ";


while (true) {
cin >> s2;
if (s2 <= 100) break;
cout << "Marks cannot exceed 100. Please re-enter: ";
}

cout << "Enter marks for Subject 3: ";


while (true) {
GET MORE SOLUTIONS FILE FROM
VUAnswer.pk
cin >> s3;
if (s3 <= 100) break;
cout << "Marks cannot exceed 100. Please re-enter: ";
}

float average = (s1 + s2 + s3) / 3.0f;

string grade;
if (average >= 90) grade = "A";
else if (average >= 80) grade = "B";
else if (average >= 70) grade = "C";
else if (average >= 60) grade = "D";
else grade = "F";

int highest = max({s1 , s2 , s3});


int lowest = min({s1 , s2 , s3});

cout << "\nMarks has been entered. Here is your result:" << endl;
cout << "Obtained marks out of 300: " << s1 + s2 + s3 << endl;
cout << "Average Marks: " << average << endl;
cout << "Grade: " << grade << endl;
cout << "Highest Mark: " << highest << endl;
cout << "Lowest Mark: " << lowest << endl;

return 0;
}
GET MORE SOLUTIONS FILE FROM
VUAnswer.pk

OUTPUT:
GET MORE SOLUTIONS FILE FROM
VUAnswer.pk

REGARD - SARIM
WHATSAPP +923162965677

PLEASE NOTE:
Don't copy-paste the same solution.
Make sure you can make some changes to your solution file before
submitting copy paste solution will be marked zero.
If you found any mistake then correct yourself and inform me.
Before submitting an assignment must check your assignment requirement
file.
If you need some help or question about file and solutions feel free to ask.

FOR MORE ASSIGNMENTS SOLUTIONS VISIT

VUAnswer.pk

You might also like