Topic: Computer Science | C++ Programming Write a C++ Program that reads in 2 in
ID: 3880309 • Letter: T
Question
Topic: Computer Science | C++ Programming Write a C++ Program that reads in 2 integers and then outputs their sum, product, remainder and average. A sample output of the program as follows:- Enter the first number:- 20 Enter the second number:- 10 20 + 10 = 30 20 * 10 = 200 (20 + 10)/2 = 15 20 % 10 = 0
To input 2 number to output results of sum, difference, product, quotient, remainder input 2 numbers output results*/
#include<iostream>
void ReadNumbers(int, int);
int CalculateSum(int, int);
double CalculateAverage(int, int);
int CalcullateRemainder(int, int);
using namespace std;
int main() { int num1, num2;
/* Read the input from the user and store in num1 and num2*/
cout << "Enter the first number :- "; cin >> num1;
cout << "Enter the second number :- "; cin >> num2;
int ReadNumbers(int&, int&); int calculateSum(int&, int&);
double CalculateAverage(int&, int&);
int Calcullteremainder(int, int);
cout << num1 << " + " << num2 << " = " << num1 + num2 << endl; /*Calculate sum by num1+num2 */
cout << num1 << " * " << num2 << " = " << num1 * num2 << endl; /*Calculate product by num1*num2 */
cout << "(" << num1 << " + " << num2 << ")/2 = " << (float)(num1 + num2) / 2 << endl; /*Calculate average by (num1+num2)/2 */
cout << num1 << " % " << num2 << " = " << num1 % num2 << endl; /*Calculate remainder by num1%num2 */ return 0; /*return from main function */
}
Rewrite the program you wrote in Problem 1,
this time make the StudentRecord type a class type rather than a struct. The student record class should hav member variables for all input datadescribed in Problem 1 and a member variable for the student's weighted average numeric score for the entire course as well as a member variable for the student's final letter grade. Make all member variables Private. Include member functions for each of the following member functions to set each of the member variables to values given as an argument(s) to the function, member functions to retrieve the data from each of the member variables, a void function that calculates the student's weighted average numeric score for the entire course and sets the corresponding member variable and a void function that calculates the student's final letter grade and sets the corresponding member variable. Please I don't understand the problem!
Please write this code in c++! Help me Please!
Explanation / Answer
#include<iostream>
using namespace std;
class StudentRecord{
private:
//assume number of subjects to be 3
int num1,num2,num3;
double avg;
char grade;
public:
//member function to assign subject marks
void set_values(int a, int b, int c){
num1=a;
num2=b;
num3=c;
}
//member function to calculate average
void calculate_avg(){
avg = (num1+num2+num3)/3;
}
//member function to assign grade according to Indian education system
void calculate_grade(){
if(avg>=90)
grade='S';
if(avg>=80&&avg<90)
grade='A';
if(avg>=70&&avg<80)
grade='B';
if(avg>=60&&avg<70)
grade='C';
if(avg>=50&&avg<60)
grade='D';
if(avg>=40&&avg<50)
grade='E';
if(avg<40)
grade='F';
}
//member functions to retrieve data
double get_average(){
return avg;
}
char get_grade(){
return grade;
}
};
int main(){
//number of students be n
int n;
cout<<"Enter number of students"<<endl;
cin>>n;
//array of objects such that n number students data can be stored
StudentRecord std[n];
for(int i=1;i<=n;i++){
cout<<"Enter the marks of student "<<i<<endl;
int a,b,c;
cin>>a>>b>>c;
//calling the member functions
std[i].set_values(a,b,c);
std[i].calculate_avg();
std[i].calculate_grade();
//calling the member functions to print the data
cout<<"Average of the student "<<i<<" = "<<std[i].get_average()<<endl;
cout<<"Grade of student "<<i<<" = "<<std[i].get_grade()<<endl;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.