Question

I am having trouble getting this program to run with 3 parts. Could I get assistance...

I am having trouble getting this program to run with 3 parts. Could I get assistance to understand this code as well?

Here is the information given.

7.20 Chapter 7A

Create the class described by the UML and directions are given below:

Student
- studentName: string
- midterm: int
- finalGrade: int
+Student()
+Student(name: string, midterm: int, fin: int)

+setMidterm(grade: int): void
+setFinal(grade: int): void
+ setStudentName(studentName: string): void

+getName():String
+getMidterm():int
+getFinal():int

+computeAverage(): double
+computeLetterGrade(): string

+printGradeReport():void

Create the class using three files - a .h, a .cpp and a main.cpp:

  • Constructor with no arguments
    • sets the string to an empty string, and all numbers to 0
  • Constructor with arguments
    • Sets the studentName, midterm and finalGrade to the values passed in
  • Get methods (accessors) return the field that the get refers to
  • Set methods (mutators) set the field to the new values passed in to it
  • computeAverage - compute the average of the midterm and finalGrade
  • computeLetterGrade - calls the computeAverage function and then computes whether the student received an A, B, C, D, or F
  • printGradeReport - prints the following grade report for each student (there are 24 asterisks)
Grade Report
************************
Name: Jorddan
Midterm Grade: 85
Final Grade: 74
Average: 79.5    B

Once you have finished the class and tested it with your main, make your main do the following: [Note: there are no loops!!!!]

  • create three student objects with the following information
    • John, midterm 84, final 93
    • Lori, midterm 74, final 81
    • Theo, midterm 96, final 94
  • print the student reports using the member function
  • print each student in a row as shown in the output below
Grade Report
************************
Name: John
Midterm Grade: 84
Final Grade: 93
Average: 88.5    B
Grade Report
************************
Name: Lori
Midterm Grade: 74
Final Grade: 81
Average: 77.5    C
Grade Report
************************
Name: Theo
Midterm Grade: 96
Final Grade: 94
Average: 95    A

Name         Average     Grade
John            88.5         B
Lori            77.5         C
Theo              95         A

Thank you for your assistance.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include<string>
using namespace std;
class Student
{
string studentName;
int midterm;
int finalGrade;
public:
Student()//default constructor
{
studentName="";
midterm=0;
finalGrade=0;
}
Student(string name,int midterm,int fin)//Parameterized Constructor
{
studentName=name;
this->midterm=midterm;
finalGrade=fin;

}
void setMidterm(int grade)//function to set midterm marks
{
midterm=grade;
}
void setFinal(int grade)//function to set Final marks
{
finalGrade=grade;
}
void setStudentName(string studentName)//Function to set student name
{
this->studentName= studentName;
}
string getName()//function to get the student name
{
return studentName;
}
int getMidterm()//function to get the midterm marks
{
return midterm;
}
int getFinal()//function to get the final marks
{
return finalGrade;
}
double computeAverage()//function to compute average of midterm and final marks
{
return (midterm+finalGrade)/2.0;
}
string computeLetterGrade()//function to compute grade according to the average marks
{ string b;
double a=computeAverage();
if(a>=90 && a<=100)
{b='A';
return b;
}
else if (a>=80 && a<=89)
{b='B';
return b;
}
else if(a>=70 && a<=79)
{b='C';
return b;
}
else if(a>=60 && a<=69)
{b='D';
return b;
}
else if(a>=50 && a<=59)
{b='E';
return b;
}

}
void printGradeReport()//To print grade report which contains details of student
{
cout<<endl;
cout<<"Grade Report"<<endl;
cout<<"************************"<<endl;
cout<<"Name: ";
cout<<studentName<<endl;
cout<<"Midterm Grade: ";
cout<<midterm<<endl;
cout<<"Final Grade: ";
cout<<finalGrade<<endl;
cout<<"Average:";
cout<<computeAverage();
cout<<" "<<computeLetterGrade();
cout<<endl;

}
};
int main() {
Student s1("John",84,93);//test case 1
Student s2("Lori",74,81);//test case 2
Student s3("Theo",96,94);//test case 3
s1.printGradeReport();//Printing grade report of student s1
s2.printGradeReport();//Printing grade report of student s2
s3.printGradeReport();//Printing grade report of student s3
cout<<endl;
//Printing the details of all the students
cout<<"Name Average Grade"<<endl;
cout<<s1.getName()<<" ";
cout<<s1.computeAverage()<<" ";
cout<<s1.computeLetterGrade()<<endl;
cout<<s2.getName()<<" ";
cout<<s2.computeAverage()<<" ";
cout<<s2.computeLetterGrade()<<endl;
cout<<s3.getName()<<" ";
cout<<s3.computeAverage()<<" ";
cout<<s3.computeLetterGrade();
return 0;
}

Add a comment
Know the answer?
Add Answer to:
I am having trouble getting this program to run with 3 parts. Could I get assistance...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hi, I am writing Java code and I am having a trouble working it out. The...

    Hi, I am writing Java code and I am having a trouble working it out. The instructions can be found below, and the code. Thanks. Instructions Here are the methods needed for CIS425_Student: Constructor: public CIS425_Student( String id, String name, int num_exams ) Create an int array exams[num_exams] which will hold all exam grades for a student Save num_exams for later error checking public boolean addGrade( int exam, int grade ) Save a grade in the exams[ ] array at...

  • This is a simple C++ class using inheritance, I have trouble getting the program to work....

    This is a simple C++ class using inheritance, I have trouble getting the program to work. I would also like to add ENUM function to the class TeachingAssistant(Derived class) which is a subclass of Student(Derived Class) which is also a subclass of CourseMember(Base Class). The TeachingAssistant class uses an enum (a user-defined data type) to keep track of the specific role the TA has: enum ta_role {LAB_ASSISTANT, LECTURE_ASSISTANT, BOTH}; You may assume for initialization purposes that the default role is...

  • I am having trouble with my Python code in this dictionary and pickle program. Here is...

    I am having trouble with my Python code in this dictionary and pickle program. Here is my code but it is not running as i am receiving synthax error on the second line. class Student: def__init__(self,id,name,midterm,final): self.id=id self.name=name self.midterm=midterm self.final=final def calculate_grade(self): self.avg=(self.midterm+self.final)/2 if self.avg>=60 and self.avg<=80: self.g='A' elif self.avg>80 and self.avg<=100: self.g='A+' elif self.avg<60 and self.avg>=40: self.g='B' else: self.g='C' def getdata(self): return self.id,self.name.self.midterm,self.final,self.g CIT101 = {} CIT101["123"] = Student("123", "smith, john", 78, 86) CIT101["124"] = Student("124", "tom, alter", 50,...

  • Greetings, everybody I already started working in this program. I just need someone to help me...

    Greetings, everybody I already started working in this program. I just need someone to help me complete this part of the assignment (my program has 4 parts of code: main.cpp; Student.cpp; Student.h; StudentGrades.cpp; StudentGrades.h) Just Modify only the StudentGrades.h and StudentGrades.cpp files to correct all defect you will need to provide implementation for the copy constructor, assignment operator, and destructor for the StudentGrades class. Here are my files: (1) Main.cpp #include <iostream> #include <string> #include "StudentGrades.h" using namespace std; int...

  • Java. Java is a new programming language I am learning, and so far I am a...

    Java. Java is a new programming language I am learning, and so far I am a bit troubled about it. Hopefully, I can explain it right. For my assignment, we have to create a class called Student with three private attributes of Name (String), Grade (int), and CName(String). In the driver class, I am suppose to have a total of 3 objects of type Student. Also, the user have to input the data. My problem is that I can get...

  • Hey guys I am having trouble getting my table to work with a java GUI if...

    Hey guys I am having trouble getting my table to work with a java GUI if anything can take a look at my code and see where I am going wrong with lines 38-49 it would be greatly appreciated! Under the JTableSortingDemo class is where I am having erorrs in my code! Thanks! :) import java.awt.*; import java.awt.event.*; import java.util.*; import java.util.List; import javax.swing.*; public class JTableSortingDemo extends JFrame{ private JTable table; public JTableSortingDemo(){ super("This is basic sample for your...

  • #ifndef STUDENTTESTSCORES_H #define STUDENTTESTSCORES_H #include <string> using namespace std; const double DEFAULT_SCORE = 0.0; class StudentTestScores...

    #ifndef STUDENTTESTSCORES_H #define STUDENTTESTSCORES_H #include <string> using namespace std; const double DEFAULT_SCORE = 0.0; class StudentTestScores { private: string studentName; // The student's name double *testScores; // Points to array of test scores int numTestScores; // Number of test scores // Private member function to create an // array of test scores. void createTestScoresArray(int size) { numTestScores = size; testScores = new double[size]; for (int i = 0; i < size; i++) testScores[i] = DEFAULT_SCORE; } public: // Constructor StudentTestScores(string...

  • Instructions: Consider the following C++ program. At the top you can see the interface for the...

    Instructions: Consider the following C++ program. At the top you can see the interface for the Student class. Below this is the implementation of the Student class methods. Finally, we have a very small main program. #include <string> #include <fstream> #include <iostream> using namespace std; class Student { public: Student(); Student(const Student & student); ~Student(); void Set(const int uaid, const string name, const float gpa); void Get(int & uaid, string & name, float & gpa) const; void Print() const; void...

  • I was wondering if I could get some help with a Java Program that I am...

    I was wondering if I could get some help with a Java Program that I am currently working on for homework. When I run the program in Eclipse nothing shows up in the console can you help me out and tell me if I am missing something in my code or what's going on? My Code: public class Payroll { public static void main(String[] args) { } // TODO Auto-generated method stub private int[] employeeId = { 5658845, 4520125, 7895122,...

  • Java Project In Brief... For this Java project, you will create a Java program for a...

    Java Project In Brief... For this Java project, you will create a Java program for a school. The purpose is to create a report containing one or more classrooms. For each classroom, the report will contain: I need a code that works, runs and the packages are working as well The room number of the classroom. The teacher and the subject assigned to the classroom. A list of students assigned to the classroom including their student id and final grade....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT