Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please fix this code. OUtput is comming diffrent and i am getting error when running test. If you fix it i will give you positive

Please fix this code. OUtput is comming diffrent and i am getting error when running test. If you fix it i will give you positive feedback. Thank you.

image text in transcribed

image text in transcribed

C++

An IMPORTANT note about numeric literals: It is OK to use literals 0 (zero) or 1 (one) to initialize variable values, but constants or variables should be used otherwise.

Besides main.cpp, Week-3 in Replit has a folder named includes with 2 files: student.h and student.cpp.

main.cpp

Enter your first and last name at the top in comments. Include file student.h be sure to include the path as it is in a different folder. Declare a constant integer named AP_STUDENTS with a value of 2. Declare a constant integer named NBR_STUDENTS with a value of 3.

Inside the main function:

Declare a Student array named students_ap with an array size of AP_STUDENTS, and initialize the student names as: Mike Miller and Linda Lawson. Declare a Student array named students with an array size of NBR_STUDENTS.

Under the code: cout

Under the code: cout

Under the code: cout

Under the code: cout

Under the code: cout

student.h

Above the code: using namespace std; Include file iostream.

Define a class named Student with

Public members:

A static constant integer named NBR_SCORES with a value of 4. Prototype the below functions: A void function named setName with 2 string parameters for first name, and last name. A void function named updateName with no parameters. A void function named setScores with no parameters. A void function named show Scores with no parameters. A constructor with 2 string parameters each with a default value of (an empty string).

Private members:

A string named firstName. A string named lastName. An integer array named scores with an array size of NBR_SCORES. An integer named studentID. A static integer named ID.

student.cpp

Include file student.h no path needed as it is in the same folder. Initialize the private static variable ID with a value of 100.

Function definitions:

Define setName to

set the private variables firstName and lastName with the values of the parameters.

Define updateName to

prompt the user for first name and last name then call setName. For example: Enter first name for student 103: Enter last name for student 103: Note: the prompts show the student ID number. Hint: you will need 2 local string variables.

Define setScores to

prompt the user for the students scores and populate the private scores array. For example: Enter score 1 for student 101: Mike Miller Note: the prompt shows which score and the student ID number and student name. Note: you must write a loop to run NBR_SCORES times.

Define showScores to

show the scores in the private scores array as well as the average for the scores. For example: Scores for student 101: Mike Miller are 100 100 99 98 The average is: 99 Note: the output shows the student ID number and student name. Note: you must write a loop to show all of the scores. Note: write just one loop to show the scores and calculate the average.

Define the constructor to

Increment the private static variable ID then assign that value to the private variable studentID Then call setName.

////////////////////////////////////////////////////////////////////////////////

int main() {

cout

cout

cout

cout

cout

cout

/********************************** // YOUR OUTPUT

// SAMPLE OUTPUT Enter scores for AP students Enter score 1 for student 101: Mike Miller 100 Enter score 2 for student 101: Mike Miller 100 Enter score 3 for student 101: Mike Miller 99 Enter score 4 for student 101: Mike Miller 98 Enter score 1 for student 102: Linda Lawson 100 Enter score 2 for student 102: Linda Lawson 98 Enter score 3 for student 102: Linda Lawson 99 Enter score 4 for student 102: Linda Lawson 92 Show scores for AP students Scores for student 101: Mike Miller are 100 100 99 98 The average is: 99 Scores for student 102: Linda Lawson are 100 98 99 92 The average is: 97 Enter names for non-AP students Enter first name for student 103: Mary Enter last name for student 103: Mills Enter first name for student 104: Jacob Enter last name for student 104: Johnson Enter first name for student 105: Tim Enter last name for student 105: Thomas Enter scores for non-AP students Enter score 1 for student 103: Mary Mills 98 Enter score 2 for student 103: Mary Mills 97 Enter score 3 for student 103: Mary Mills 96 Enter score 4 for student 103: Mary Mills 95 Enter score 1 for student 104: Jacob Johnson 87 Enter score 2 for student 104: Jacob Johnson 86 Enter score 3 for student 104: Jacob Johnson 85 Enter score 4 for student 104: Jacob Johnson 84 Enter score 1 for student 105: Tim Thomas 76 Enter score 2 for student 105: Tim Thomas 75 Enter score 3 for student 105: Tim Thomas 74 Enter score 4 for student 105: Tim Thomas 73 Show scores for non-AP students Scores for student 103: Mary Mills are 98 97 96 95 The average is: 96 Scores for student 104: Jacob Johnson are 87 86 85 84 The average is: 85 Scores for student 105: Tim Thomas are 76 75 74 73 The average is: 74

Goodbye ***********************************/

main.cpp

// Enter your first and last name here

#include

#include "includes/student.h"

using namespace std;

const int AP_STUDENTS = 2;

const int NBR_STUDENTS = 3;

int main() {

Student students_ap[AP_STUDENTS] = {Student("Mike", "Miller"), Student("Linda", "Lawson")};

Student students[NBR_STUDENTS];

cout

for (int i = 0; i

students_ap[i].setScores();

}

cout

for (int i = 0; i

students_ap[i].showScores();

}

cout

for (int i = 0; i

students[i].updateName();

}

cout

for (int i = 0; i

students[i].setScores();

}

cout

for (int i = 0; i

students[i].showScores();

}

return 0;

}

student.h:

#ifndef STUDENT_H

#define STUDENT_H

#include

using namespace std;

class Student {

public:

static const int NBR_SCORES = 4;

void setName(string firstName, string lastName);

void updateName();

void setScores();

void showScores();

Student(string firstName = "", string lastName = "");

private:

string firstName;

string lastName;

int scores[NBR_SCORES];

int studentID;

static int ID;

};

#endif

student.cpp:

#include "student.h"

int Student::ID = 100;

Student::Student(string firstName, string lastName) {

studentID = ID++;

setName(firstName, lastName);

}

void Student::setName(string firstName, string lastName) {

this->firstName = firstName;

this->lastName = lastName;

}

void Student::updateName() {

string first, last;

cout

getline(cin, first);

cout

getline(cin, last);

setName(first, last);

}

void Student::setScores() {

for (int i = 0; i

cout

cin >> scores[i];

}

}

void Student::showScores() {

cout

int sum = 0;

for (int i = 0; i

cout

sum += scores[i];

}

double avg = sum / static_cast(NBR_SCORES);

cout

}

Stop Input/Output Tests

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

More Books

Students also viewed these Databases questions

Question

Discuss the Rights issue procedure in detail.

Answered: 1 week ago

Question

Discuss the Rights issue procedure in detail.

Answered: 1 week ago

Question

Explain the procedure for valuation of shares.

Answered: 1 week ago

Question

Which months of this year 5 Mondays ?

Answered: 1 week ago

Question

Define Leap year?

Answered: 1 week ago