The document contains two programming assignments for a Programming Fundamentals course. The first program is a simple calculator implemented in C++ using if-else statements, while the second program calculates and displays a student's grade based on their scores in Computer Science, Math, and English. Both programs include input validation and output messages for user feedback.
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 ratings0% found this document useful (0 votes)
3 views4 pages
C^M^M PROGRAM
The document contains two programming assignments for a Programming Fundamentals course. The first program is a simple calculator implemented in C++ using if-else statements, while the second program calculates and displays a student's grade based on their scores in Computer Science, Math, and English. Both programs include input validation and output messages for user feedback.
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/ 4
ASSIGNMENT NO :2
DEPARTMENT: BSCS (1ST SMESTER FALL 2024)
SUBJECT: PROGRAMMING FUNDAMENTALS (THEORY)
SUBMITTED BY: MENAHIL ZUBAIR
REG NO: 1240100954
SUBMITTED TO: MA’AM MALAIKA PASHA
SUBMISSION DATE: 31-12-24
Topic: Program in C++ Program no:1Write a program to create a simple calculator using *if-else* statements. #include<iostream> using namespace std; int main(){ char operation; float num1,num2; cout<< "Enter an opreator(+,-,*,/)"<<endl; cin>>operation; cout<< "Enter a number"<<endl; cin>> num1; cout<<"enter a second number"<<endl; cin >> num2; if(operation=='+'){ cout<< "Result:" << num1+num2 << endl; } else if (operation=='-'){ cout<<"Result:" << num1-num2 << endl; } else if (operation=='*'){ cout<< "Result:"<< num1*num2 << endl; } else if (operation=='/'){ if(num2==0){ cout<<"Error:Division by zero is not allowed."<< endl; }else{ cout << "Result:"<<num1/num2 << endl; } } else { cout << "Error:Invalid opreator." << endl; } return 0; }
Program no 2: write a program that calculates and displace
the grade for a student based on their scores in different courses: #include <iostream> using namespace std; int main() { int Computer Science, Math, English; float average; char grade; cout << "Enter Computer Science score: "; cin >> Computer Science; cout << "Enter Math score: "; cin >> Math; cout << "Enter English score: "; cin >> English; if (Computer Science < 0 || Computer Science > 100 || Math < 0 || Math > 100 || English < 0 || English > 100) { cout << "Invalid scores! Please enter values between 0 and 100." << endl; return 0; } average = (ComputerScience + Maths + English) / 3.0; 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'; cout << "Average: " << average << endl; cout << "Grade: " << grade << endl;