# Structure and Algorithms

Lab 4

0. Build and run Lab4.cpp

// Student

// Name: <Your name here>

///Section; << Your Section name>>

// ID: <Your ID here>

// example: class constructor

#include <iostream>

using namespace std;

class Student {

private:

string name;

int idNum;

double gpa;

public:

Student ( ) { } //initialize student object;

Student(string, int, double);

string getName( )

{

// Return the name of the student

// [Add code here]

}

// Write a function called getGPA that returns the GPA of the student.

// [Add code here]

// Write a function called getIdNum that returns the idNum

// of the student.

// [Add code here]

// Mutator: changes the student name

void setStudentName(string n)

{

// [Add code here]

}

// Write a mutator called setGPA, which takes a double

// and changes the GPA of the student.

// [Add code here]

// call user defined toString function Returns a formatted string of student

// information, as shown in the sample output.

string formatString()

{

// Return the formatted String.

// [Add code here]

}

};

Student::Student(string a, int b, double c) {

// Save namePar to class variable name

// [Add code here]

// Save idNumPar to class variable idNum

// [Add code here]

// Save gpaPar to class variable gpa

// [Add code here]

} //End of Student :: Student

int main ( )

{

// Constants

const string NAME = // [your name here];

const int STUID = // [Your id here];

const double GPA1 = 4.00;

const double GPA2 = 2.34;

Student stu1;

stu1 = Student(NAME, STUID, GPA1);

cout << “\nName: ” << stu1.getName();

cout << “Id Number: ” + stu1.getIdNum();

cout << “GPA: ” + stu1.getGPA());

stu1.setGPA(GPA2);

cout << stu1.formatString();

// Create a second student object

// With a name of Pistol Pete, a gpa of 4.00,

// and a student Id of 000000001

// [Your code here]

// Print out this student similar to above.

// You do not need to reset the gpa of this student.

// [Your code here]

system(“pause”); // In case of Visual studio users

return 0;

} // end of main

1.2 There is still quite a bit of code that needs to be filled in for the program to work properly.

1.3 Run the program and output must be captured to Lab4out.doc. A Sample output is below. Note that the program prints out the stats for the two students (you and Pistol Pete) twice, the first time by getting and printing each attribute of the student, and another time by just printing the student, which calls “formatString” on it.

1.4 Hand in

Lab4.cpp and Lab4out.doc