Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++ problem, need .h and .cpp and main.cpp; here is start code: ************************************************************************************ student.h #ifndef STUDENT_H #define STUDENT_H /** * Definition of the Student class.

c++ problem, need .h and .cpp and main.cpp;

here is start code:

************************************************************************************

student.h

#ifndef STUDENT_H

#define STUDENT_H

/**

* Definition of the Student class.

* Provided as part of the Composition of Objects lab.

*/

#include

#include

#include

class Student {

public:

Student( ) = default;

Student( std::string name, int id );

~Student( );

std::string get_name( ) const;

int get_id( ) const;

double get_exam_score( int exam_number ) const;

double get_average( ) const;

double get_exam_count( ) const;

char get_letter_grade( ) const;

void set_name( std::string name );

void set_id( int id );

void set_exam_score( int exam_number, double score );

void add_exam_score( double score );

std::ostream& write( std::ostream& strm = std::cout ) const;

private:

std::string _name;

int _id{0};

std::vector _exams;

};

#endif

*************************************************************************************************

student.cpp

/**

* Implementation for the Student class,

* provided as part of the Composition of Objects lab.

*/

#include "Student.h"

#include

/**

* Construct a student given the name and ID number

*

* @param name student name

* @param id student ID number

*/

Student::Student( std::string name, int id ) : _name{name}, _id{id} {}

/**

* Provides output on stderr when student leaves scope for

* debugging purposes only.

*/

Student::~Student( ) {

std::cerr

}

/**

* Accessor for student's name.

*

* @return student's name

*/

std::string Student::get_name( ) const {

return _name;

}

/**

* Accessor for student ID.

*

* @return student's ID

*/

int Student::get_id( ) const {

return _id;

}

/**

* Accessor for a particular exam score, given the exam number,

* which starts counting from 1.

*

* @param exam_number Exam number (Natural number, starts at 1.)

* @return the score of exam number `exam_number`

*/

double Student::get_exam_score( int exam_number ) const {

return _exams.at( exam_number - 1 );

}

/**

* Mutator allowing the student name to be changed.

*

* @param name new name for the student

*/

void Student::set_name( std::string name ) {

_name = name;

}

/**

* Mutator allowing the student ID to be changed.

*

* @param id new ID number for the student

*/

void Student::set_id( int id ) {

_id = id;

}

/**

* Mutator allowing a selected exam score to be updated, given

* the exam number (starting from 1) and the new score.

*

* @param exam_number Exam number (Natural number, starts at 1.)

* @param score the updated score to store

*/

void Student::set_exam_score( int exam_number, double score ) {

_exams.at( exam_number - 1 ) = score;

}

/**

* Adds a new exam score for the student, as the last of their

* exams.

*

* @param score value of new score to add

*/

void Student::add_exam_score( double score ) {

_exams.push_back( score );

}

/**

* Accessor for the student's overall exam average.

*

* @remarks The exam average is assumed to be 100% if

* no exams have been entered yet.

*

* @return student's current exam average

*/

double Student::get_average( ) const {

auto sum{0.0};

for ( const auto& score : _exams ) { sum += score; }

return _exams.size( ) > 0 ? sum / _exams.size( ) : 100.0;

}

/**

* Accessor for the number of exams the student has

* taken.

*

* @return the number of exams stored for this student

*/

double Student::get_exam_count( ) const {

return _exams.size( );

}

/**

* Accessor for the student's current letter grade.

*

* @remarks Uses the scale:

* >= 90 : A

* [80, 90) : B

* [70, 80) : B

* [60, 70) : B

*

*

* @return [description]

*/

char Student::get_letter_grade( ) const {

auto grade = 'F';

auto avg = get_average( );

if ( avg >= 90.0 )

grade = 'A';

else if ( avg >= 80.0 )

grade = 'B';

else if ( avg >= 70.0 )

grade = 'C';

else if ( avg >= 60.0 )

grade = 'D';

return grade;

}

/**

* Writes a string describing the student (name, ID, average, and letter

* grade) to the stream specified by `strm`. The default is stdout.

*

* @param strm stream to write into (default = stdout)

* @return the modified stream `strm` is returned

*/

std::ostream& Student::write( std::ostream& strm ) const {

strm

return strm;

}

*****************************************************************************************************************

image text in transcribedimage text in transcribed

Begin by adding the empty.txt files listed below to the project oop04in.txt oop04out.txt Create studentArrayv4 methods read (),write ), and add from) as follows: VO int ostream& void add const Student& new_student read( istream& infile write ( add from( istream& infile ostream& out file=cout ) const; The add() method shown here is an overloaded add (). It will take a student object [by const reference) and add it to the array, using the same rules as the zero-parameter add () That is, if there is room left in the physical array, the new student is added at the end. If the physical array is full, its size should be increased by 3 (by allocating a new array and copying over the existing pointers) and then the new student should be added at the end of the logical array. (Refer back to the material from the in-lab if needed.) When you finish this version of add. you might be able to re-factor the version of add) you wrote in lab to make use of it so that there is no repeated code. The read () method invokes method add from), creating new Student objects one at a time, until the end of the input stream is reached; the number of Students that were successfully read should be returned. The add from() method will accept the input file as a parameter, and is responsible for extracting all available data for the student, creating that student, and adding the student to the StudentArrayv4 collection using the overloaded add() method described above. This method should add a student only if there is enough valid information in the stream to constitute a student record. For our purposes, if the stream contains at least a valid name and id number, the record is valid [see the input file specification below for more specifics). The write () method should replace the write() method you created in lab. It will direct the printing of each Student object's data to the indicated stream (the format is shown later in this text). Write the test data file oop04in.txt and make sure the methods work correctly with it. Example contents might include the following. Able: Baker 777 71 73 75 Charles: 888 81 83 85 Dunlap: 999 91 93 95 666 61 63 65 You do not know in advance how many students may be in the input file, or how many exam scores each student will have (and not all students need have the same number of exams). The format does guarantee the following: Each line represents one student. The student name is first, followed by a colon. Name is required. e The student ID number is next, possibly preceded by some amount of whitespace, which must be ignored. Student ID is required. Following the student ID will be zero or more exam scores, separated by some amount of whitespace. Scores are optional. Function main() should prompt the user for the names of files to be read and written. Add code to main() to open the input and output files, and perform testing for the new functionality you are adding. Begin by adding the empty.txt files listed below to the project oop04in.txt oop04out.txt Create studentArrayv4 methods read (),write ), and add from) as follows: VO int ostream& void add const Student& new_student read( istream& infile write ( add from( istream& infile ostream& out file=cout ) const; The add() method shown here is an overloaded add (). It will take a student object [by const reference) and add it to the array, using the same rules as the zero-parameter add () That is, if there is room left in the physical array, the new student is added at the end. If the physical array is full, its size should be increased by 3 (by allocating a new array and copying over the existing pointers) and then the new student should be added at the end of the logical array. (Refer back to the material from the in-lab if needed.) When you finish this version of add. you might be able to re-factor the version of add) you wrote in lab to make use of it so that there is no repeated code. The read () method invokes method add from), creating new Student objects one at a time, until the end of the input stream is reached; the number of Students that were successfully read should be returned. The add from() method will accept the input file as a parameter, and is responsible for extracting all available data for the student, creating that student, and adding the student to the StudentArrayv4 collection using the overloaded add() method described above. This method should add a student only if there is enough valid information in the stream to constitute a student record. For our purposes, if the stream contains at least a valid name and id number, the record is valid [see the input file specification below for more specifics). The write () method should replace the write() method you created in lab. It will direct the printing of each Student object's data to the indicated stream (the format is shown later in this text). Write the test data file oop04in.txt and make sure the methods work correctly with it. Example contents might include the following. Able: Baker 777 71 73 75 Charles: 888 81 83 85 Dunlap: 999 91 93 95 666 61 63 65 You do not know in advance how many students may be in the input file, or how many exam scores each student will have (and not all students need have the same number of exams). The format does guarantee the following: Each line represents one student. The student name is first, followed by a colon. Name is required. e The student ID number is next, possibly preceded by some amount of whitespace, which must be ignored. Student ID is required. Following the student ID will be zero or more exam scores, separated by some amount of whitespace. Scores are optional. Function main() should prompt the user for the names of files to be read and written. Add code to main() to open the input and output files, and perform testing for the new functionality you are adding

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Marketing The Ultimate Marketing Tool

Authors: Edward L. Nash

1st Edition

0070460639, 978-0070460638

More Books

Students also viewed these Databases questions

Question

3. Who would the members be?

Answered: 1 week ago

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago