Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For the first part of the lab, I want to make sure you have a solid understanding of the fundamentals in C++. To verify that,

For the first part of the lab, I want to make sure you have a solid understanding of the fundamentals in C++. To verify that, I have created a fileimage text in transcribed that contains the starting code. Using this file, finish implementing the three functions needed for the program to run.

If you managed to do this correctly, you should be able to replicate the following session:

Enter the name for student #1: Patricia Perez Enter the age for student #1: 29 Enter the name for student #2: Carmen Enter the age for student #2: 23 Enter the name for student #3: Albert DeLeon Enter the age for student #3: 16 Enter the name for student #4: Brandon W Perry Enter the age for student #4: 54 Enter the name for student #5: Nicole Henderson Enter the age for student #5: 30 Student #1 Name: Patricia Perez Age: 29 Student #2 Name: Carmen Age: 23 Student #3 Name: Albert DeLeon Age: 18 Student #4 Name: Brandon W Perry Age: 50 Student #5 Name: Nicole Henderson Age: 30

Basic Class Operations

For the second part of the lab, the first thing to do is implement a Student class. You need to use class separation (i.e., create a Student.h and a Student.cpp file) and have include guards. The UML diagram for the Student class is as follows:

UML diagram for Student class
Student
- name : string - age : int
+ Student() + ~Student() + setName(s : string) : void + setAge(i : int) : void + getName() const : string + getAge() const : int

The implementation details should be straightforward. To avoid having empty bodies for the constructor and destructor, you should write a cout statement in each of them. For the constructor, make it display the message "Student object created!". For the destructor, make it display the message "Student object destroyed!".

After creating the Student class, turn your attention to a modified versionimage text in transcribed of the main file from part one. Once again, you will need to finish implementing the three functions needed for the program to run.

If you managed to do this correctly, you should be able to replicate the following session:

Student object created! Student object created! Student object created! Student object created! Student object created! Enter the name for student #1: Patricia Perez Enter the age for student #1: 29 Enter the name for student #2: Carmen Enter the age for student #2: 23 Enter the name for student #3: Albert DeLeon Enter the age for student #3: 16 Enter the name for student #4: Brandon W Perry Enter the age for student #4: 54 Enter the name for student #5: Nicole Henderson Enter the age for student #5: 30 Student #1 Name: Patricia Perez Age: 29 Student #2 Name: Carmen Age: 23 Student #3 Name: Albert DeLeon Age: 18 Student #4 Name: Brandon W Perry Age: 50 Student #5 Name: Nicole Henderson Age: 30 Student object destroyed! Student object destroyed! Student object destroyed! Student object destroyed! Student object destroyed!

#include

#include

using namespace std;

/*******************************************************************************

* Function Prototypes

*******************************************************************************/

void getInput(string[], int[], const int);

int modify(int);

void display(const string[], const int[], const int);

/*******************************************************************************

* int main()

* Starting point of the program.

*

* Output:

* An integer to signal to the OS the exit code.

*******************************************************************************/

int main() {

// variables

const int SIZE = 5;

string names[SIZE];

int ages[SIZE];

// get input from the user

getInput(names, ages, SIZE);

// modify the ages for certain students

// uses a range-based for loop with a reference variable

for (int& i : ages) {

i = modify(i);

}

// display the modified information back to the user

display(names, ages, SIZE);

// terminate

return 0;

}

/*******************************************************************************

* void getInput(string names[], int ages[], const int SIZE)

* Use a for loop to prompt the user for the name/age of each student. Store

* the information in the appropriate array.

*

* Inputs:

* names - a string array for storing the students' names

* ages - an integer array for storing the students' ages

* SIZE - a constant integer that represents the size of the two arrays

*******************************************************************************/

void getInput(string names[], int ages[], const int SIZE) {

}

/*******************************************************************************

* int modify(int i)

* Modifies the age for students below 18 or above 50. Students younger than 18

* should have their age bumped up to 18. Students older than 50 should have

* their age bumped down to 50. Students that do not meet the criteria do not

* have their age modified.

*

* Input:

* i - the actual age of the student

*

* Output:

* The modified age of the student.

*******************************************************************************/

int modify(int i) {

}

/*******************************************************************************

* void display(const string names[], const int ages[], const int SIZE)

* Use a while loop to display the information about the students stored in the

* two arrays.

*

* Inputs:

* names - a string array for storing the students' names

* ages - an integer array for storing the students' ages

* SIZE - a constant integer that represents the size of the two arrays

*******************************************************************************/

void display(const string names[], const int ages[], const int SIZE) {

}

MODIFIED VERSION:

#include "Student.h"

/*******************************************************************************

* Function Prototypes

*******************************************************************************/

void getInput(Student[], const int);

int modify(int);

void display(const Student[], const int);

/*******************************************************************************

* int main()

* Starting point of the program.

*

* Output:

* An integer to signal to the OS the exit code.

*******************************************************************************/

int main() {

// variables

const int SIZE = 5;

Student objArray[SIZE];

// get input from the user

getInput(objArray, SIZE);

// modify the ages for certain students

// uses a range-based for loop with a reference variable

for (Student& s : objArray) {

s.setAge(modify(s.getAge()));

}

// display the modified information back to the user

display(objArray, SIZE);

// terminate

return 0;

}

/*******************************************************************************

* void getInput(Student objArray[], const int SIZE)

* Use a for loop to prompt the user for the name/age of each student. Store

* the information in the appropriate object.

*

* Inputs:

* objArray - an array of Student objects

* SIZE - a constant integer that represents the size of the array

*******************************************************************************/

void getInput(Student objArray[], const int SIZE) {

}

/*******************************************************************************

* int modify(int i)

* Modifies the age for students below 18 or above 50. Students younger than 18

* should have their age bumped up to 18. Students older than 50 should have

* their age bumped down to 50. Students that do not meet the criteria do not

* have their age modified.

*

* Input:

* i - the actual age of the student

*

* Output:

* The modified age of the student.

*******************************************************************************/

int modify(int i) {

}

/*******************************************************************************

* void display(const Student objArray[], const int SIZE)

* Use a while loop to display the information about the students stored in the

* object array.

*

* Inputs:

* objArray - an array of Student objects

* SIZE - a constant integer that represents the size of the array

*******************************************************************************/

void display(const Student objArray[], const int SIZE) {

}

Transcribed image text

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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