Hi, I am having some trouble with my c++ homework question. I have provided my code for the question below. #include #include using namespace std; class Student{ private: string name; int exam_1grade,exam_2grade; double calcGPA(){ return (exam_1grade + exam_2grade)/2.0; } public: Student(){ name =" "; exam_1grade = 0; exam_2grade = 0; } Student(string name, int Exam1, int Exam2){ name = name; exam_1grade = Exam1; exam_2grade = Exam2; } void setName(string n) { name = n; } void setExam1(int Exam1){ exam_1grade = Exam1; } void setExam2(int Exam2){ exam_2grade=Exam2; } string setName(){ return name; } int getExam1(){ return exam_1grade; } int getExam2(){ return exam_2grade; } string getGrade(){ double gpa = calcGPA(); if(gpa >= 90 ) return "A"; else if(gpa >= 80 ) return "B"; else if(gpa >= 70 ) return "C"; else if(gpa >= 60 ) return "D"; else return "F"; } }; int main(){ Student a; a.setName("David"); a.setExam1(90); a.setExam2(80); cout<<"Name: "<
Addition of Two Numbers
Adding two numbers in programming is essentially the same as adding two numbers in general arithmetic. A significant difference is that in programming, you need to pay attention to the data type of the variable that will hold the sum of two numbers.
C++
C++ is a general-purpose hybrid language, which supports both OOPs and procedural language designed and developed by Bjarne Stroustrup. It began in 1979 as “C with Classes” at Bell Labs and first appeared in the year 1985 as C++. It is the superset of C programming language, because it uses most of the C code syntax. Due to its hybrid functionality, it used to develop embedded systems, operating systems, web browser, GUI and video games.
Hi, I am having some trouble with my c++ homework question. I have provided my code for the question below.
#include<iostream>
#include<string>
using namespace std;
class Student{
private:
string name;
int exam_1grade,exam_2grade;
double calcGPA(){
return (exam_1grade + exam_2grade)/2.0;
}
public:
Student(){
name =" ";
exam_1grade = 0;
exam_2grade = 0;
}
Student(string name, int Exam1, int Exam2){
name = name;
exam_1grade = Exam1;
exam_2grade = Exam2;
}
void setName(string n) {
name = n;
}
void setExam1(int Exam1){
exam_1grade = Exam1;
}
void setExam2(int Exam2){
exam_2grade=Exam2;
}
string setName(){
return name;
}
int getExam1(){
return exam_1grade;
}
int getExam2(){
return exam_2grade;
}
string getGrade(){
double gpa = calcGPA();
if(gpa >= 90 ) return "A";
else if(gpa >= 80 ) return "B";
else if(gpa >= 70 ) return "C";
else if(gpa >= 60 ) return "D";
else return "F";
}
};
int main(){
Student a;
a.setName("David");
a.setExam1(90);
a.setExam2(80);
cout<<"Name: "<<a.setName()<<endl;
cout<<"Exam1 grade: "<< a.getExam1()<<endl;
cout<<"Exam2 grade: "<< a.getExam2()<<endl;
cout<<"Final Grade: "<< a.getGrade()<<endl;
}
Using the class from problem 1, replace main with the following:
a. Implement a partially filled array of type Student named students of capacity
10.
b. Implement a non-member addStudent() function that:
1. Creates a new student with data populated by input parameters.
2. Adds the new student to the students array.
c. Implement a non-member output() function that:
1. Outputs all student data in the students array as displayed in the output
example (see next page).
d. Main should use the addStudent and output functions to create five students
and display their content to the console (see next page).
f. Test all functions use following main.
int main(){
int capacity = 10;
Student students[capacity];
int num = 0;
addStudent(students,capacity,num,"Amy",95,90);
addStudent(students,capacity,num,"Bob",74,63);
addStudent(students,capacity,num,"Charlie",86,80);
addStudent(students,capacity,num,"Daisy",75,90);
addStudent(students,capacity,num,"Edward",24,66);
output(students,num);
}
Output Example
Name: Amy
Exam 1: 95
Exam 2: 90
GPA: A
Name: Bob
Exam 1: 74
Exam 2: 63
GPA: D
Name: Charlie
Exam 1: 86
Exam 2: 80
GPA: B
Name: Daisy
Exam 1: 75
Exam 2: 99
GPA: B
Name: David
Exam 1: 24
Exam 2: 66
GPA: F
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images