Question

Create a class called Student. This class will hold the first name, last name, and test...

Create a class called Student. This class will hold the first name, last name, and test grades for a student. Use separate files to create the class (.h and .cpp)

Private Variables

  • Two strings for the first and last name

  • A float pointer to hold the starting address for an array of grades

  • An integer for the number of grades

Constructor

  • This is to be a default constructor

  • It takes as input the first and last name, and the number of grades.

  • It sets the name variables and the integer variable for the size

  • It allocates memory for the grades array based on the number of grades passed in

Destructor

  • free up memory associated with the array for the grades

A public method to enter the grades one at a time.

  • This is a void method.

  • The input is a float for the grade and an integer for the location in the grade array

  • The method places the grade in the appropriate spot in the array

A public method that returns a specific grade

  • This is a float method

  • Input is an index number into the grade array

  • Returns the grade at the index number passed in

A public method to compute the average

  • This is a float method

  • Returns the average of all the grades

A public method to return the full name of the student

  • Has no inputs

  • returns a string of the student's full name

Main function

  • Ask the user to enter the first name, last name, and number of grades for a student

  • Create a student instance and pass the user entered information to the constructor

  • Using a loop ask the user to enter all the grades for the student. Place that data in the instance using the appropriate method

  • Using the appropriate method, print the full name of the student

  • Using a for loop and the appropriate method print out all the grades of a student

  • Using the appropriate method, print out the average grade of the student

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

#include <iostream>
#include <string>

using namespace std;

//Student class
class Student{
//private variables
private   :
   string firstName, lastName;
   float* grades;
   int noOfGrades;

public:
   //default constructor
   Student(string _firstName, string _lastName, int _noOfGrades){
       firstName = _firstName;
       lastName = _lastName;
       noOfGrades = _noOfGrades;
       grades = new float[_noOfGrades];
   }
   //destructor to delete the dynamically allocated grades array
   ~Student(){
       delete[] grades;
   }
   //method to set a particular grade
   void setGrade(float grade, int index){
       grades[index] = grade;
   }
   //method to get a particular grade at the given index
   float getGrade(int index){
       return grades[index];
   }
   //method to compute the average of the grades
   float getAverage(){
       float totalMarks = 0;
       for(int i = 0; i < noOfGrades; i++){
           totalMarks += grades[i];
       }
       return totalMarks/noOfGrades;
   }

   //method to return the full name of the student
   string getName(){
       string fullName = firstName + " " + lastName;
       return fullName;
   }
};

//main method to show the working of above student class
int main(){

   //variable to get the values from the user
   string firstName, lastName;
   int noOfGrades;

   //taking information from the user
   cout << "Enter the first name of the Student : ";
   cin >> firstName;
   cout << "\nEnter the last name of the Student : ";
   cin >> lastName;
   cout << "\nEnter the number of grades : ";
   cin >> noOfGrades;

   //creating a instance of the Student class
   Student student(firstName,lastName,noOfGrades);
   cout << "\nEnter the Grades of the Student :\n";

   //for loop to set the grades of the student from the user
   float grade;
   for(int i = 0; i < noOfGrades; i++){
       cin >> grade;
       student.setGrade(grade,i);
   }

   //printing the details using appropriate methods

   //using getName method to print the full name of the student
   cout << "\nName of the Student is : " << student.getName();

   //using getGrade method to print all the grades of the student inside a for loop
   cout << "\nGrades of the Student are :\n";
   for(int i = 0; i < noOfGrades; i++){
       cout << student.getGrade(i) << "\n";
   }

   //using getAverage method to print the average of grades
   cout << "\nAverage of Grades is :" << student.getAverage();
}

Ouput:

Enter the first name of the Student Aman Enter the last name of the Student : Sharma Enter the number of grades : 5 Enter the

Add a comment
Know the answer?
Add Answer to:
Create a class called Student. This class will hold the first name, last name, and test...
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
  • Create a java class for an object called Student which contains the following private attributes: a...

    Create a java class for an object called Student which contains the following private attributes: a given name (String), a surname (family name) (String), a student ID number (an 8 digit number, String or int) which does not begin with 0. There should be a constructor that accepts two name parameters (given and family names) and an overloaded constructor accepting two name parameters and a student number. The constructor taking two parameters should assign a random number of 8 digits....

  • Write a class called Student. The specification for a Student is: Three Instance fields name -...

    Write a class called Student. The specification for a Student is: Three Instance fields name - a String of the student's full name totalQuizScore - double numQuizesTaken - int Constructor Default construtor that sets the instance fields to a default value Parameterized constructor that sets the name instance field to a parameter value and set the other instance fields to a default value. Methods setName - sets or changes the student name by taking in a parameter getName - returns...

  • Java - In NetBeans IDE: • Create a class called Student which stores: - the name...

    Java - In NetBeans IDE: • Create a class called Student which stores: - the name of the student - the grade of the student • Write a main method that asks the user for the name of the input file and the name of the output file. Main should open the input file for reading . It should read in the first and last name of each student into the Student’s name field. It should read the grade into...

  • Create a Business class: Instance variables: Student id 1000 - 9999 Student name Present Student email...

    Create a Business class: Instance variables: Student id 1000 - 9999 Student name Present Student email address Present Number of hours 3.5 - 18 Two constructors should be coded, one that accepts no arguments and sets every field to its default value, and one that accepts all four fields, and assigns the passed values into the instance variables. For each instance variable create two methods; a getter and a setter. Add a static method to the class that will accept...

  • using C# Write a program which calculates student grades for multiple assignments as well as the...

    using C# Write a program which calculates student grades for multiple assignments as well as the per-assignment average. The user should first input the total number of assignments. Then, the user should enter the name of a student as well as a grade for each assignment. After entering the student the user should be asked to enter "Y" if there are more students to enter or "N" if there is not ("N" by default). The user should be able to...

  • *** C++ *** Create a class called Student that contains a first name ( string) and...

    *** C++ *** Create a class called Student that contains a first name ( string) and an student id number (type long).     1. Include a member function called get_data( ) to get data from the user for insertion into the object,     2. Also include a function called display_data( ) that displays the student data. Then write a complete program that uses the class to do some computation. Your main function, main( ), should create a Dynamic Array of...

  • Part I (20%) [File: Student.java] Create a class called Student that has the following stored properties:...

    Part I (20%) [File: Student.java] Create a class called Student that has the following stored properties: • StudentID • First Name • Last Name Class Student should have read/write properties, constructor(s) and should implement the Academic interface. For academic methods, return zero for average, zero for credits and false for graduate. Also implement the toString() method that returns the above information as a String. Part II (5%) [File: Academic.java] Create an interface Academic that declares three methods: 1. average -...

  • Create a class called Employee that includes three instance variables—a first name, a last name, and...

    Create a class called Employee that includes three instance variables—a first name, a last name, and a monthly salary. Code the default (no-args, empty) constructor. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its value.

  • Using your Dog class from earlier this week, complete the following: Create a new class called...

    Using your Dog class from earlier this week, complete the following: Create a new class called DogKennel with the following: Instance field(s) - array of Dogs + any others you may want Contructor - default (no parameters) - will make a DogKennel with no dogs in it Methods: public void addDog(Dog d) - which adds a dog to the array public int currentNumDogs() - returns number of dogs currently in kennel public double averageAge() - which returns the average age...

  • A teacher wants to create a list of students in her class. Using the existing Student...

    A teacher wants to create a list of students in her class. Using the existing Student class in this exercise. Create a static ArrayList called classList that adds a student to the classList whenever a new Student is created. In the constructor, you will have to add that Student to the ArrayList. Coding below was given to edit and use public class ClassListTester { public static void main(String[] args) { //You don't need to change anything here, but feel free...

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