Build a normalized student record system. Create a class to represent student da
ID: 3566441 • Letter: B
Question
Build a normalized student record system. Create a class to represent student data. You will also create classes to handle other specific types of data including dates and addresses. Your system will include all the necessary header files, cpp files, and a main program to incorporate the larger system.
Details
Imagine a university wants to keep track of the following data about each student:
It is obvious that we will need a student class to contain all this data. However, the principles of data design indicate that the address should be its own class, as should the date. Your program should then have at least three classes: address, date, and student. Student will have two instances of date and one of address among its data members.
Process
Build all the classes you will need for this project. Each class should have a separate header file. This file contains only the class definition. Ensure your headers use the #ifndef structure described in lecture, and include whatever other headers they need.
Build a cpp file for each class which contains the code implementation of the class. This code file will include the class header file and any other headers and libraries needed.
Build a main program that imports all the needed classes and tests them. You'll then modify this program.
Create a makefile to control the compilation process. The instructor will test the program by running the make utility, so be sure your makefile works. If you use a visual editor like code::blocks, you'll still need to create and test a makefile for your project.
The complete project
When the classes are done, create a main program which does the following:
Here is the format you may use for a line of student data in your text file:
"f_name","l_name","address","dob_day","dob_month","dob_year","comp_day","comp_month","comp_year","gpa","cred_hours"
Here is an example of what it may look like:
Fry,Lock,123 Hillside Drive North Brunswick NJ 57237,08,22,1970,05,15,2012,4.00,90
Turning it in
This project will consist of a number of smaller files. You'll have a .cpp and a .h file for each class, a main.cpp file, a data file, and a makefile. Please turn in all files. Be sure all your files are properly documented.
Explanation / Answer
HeaderFiles:
Address Class:
#ifndef string
#define string
#include <string>
#endif
class Address {
private:
string Line1;
string Line2;
string City;
string State;
int Zip;
public:
//Get/Accessor functions
string GetLine1();
string GetLine2();
string GetCity();
string GetState();
int GetZip();
//Set/Mutator functions
void SetLine1( string );
void SetLine2( string );
void SetCity( string );
void SetState( string );
void SetZip( int );
void SetAddress(string,string,string,string, int);
//constructors
Address();
};
Date Class
class Date {
private:
int Year;
int Month;
int Day;
public:
//Get/Accessor functions
int GetYear();
int GetMonth();
int GetDay();
//Set/Mutator functions
void SetYear( int );
void SetMonth(int );
void SetDay(int );
void SetDate(int,int,int);
//constructors
Date();
};
Name Class
#ifndef string
#define string
#include <string>
#endif
class Name {
private:
string FirstName;
string LastName;
public:
//Get/Accessor functions
string GetFirstName();
string GetLastName();
//Set/Mutator functions
void SetFirstName( string );
void SetLastName( string );
void SetFullName(string,string);
//constructors
Name();
};
Prformance Class
class Performance {
private:
float GPA;
int Credits;
public:
//Get/Accessor functions
float GetGPA();
int GetCredits();
//Set/Mutator functions
void SetGPA( float );
void SetCredits( int );
void SetPerformance(float,int);
//constructors
Performance();
};
Studnt Class
#ifndef string
#define string
#include <string>
#endif
#ifndef Address
#define Address
#include "Address.h"
#endif
#ifndef Date
#define Date
#include "Date.h"
#endif
#ifndef Name
#define Name
#include "Name.h"
#endif
#ifndef Performance
#define Performance
#include "Performance.h"
#endif
class Student {
private:
Name SName;
Address SAddress;
Date SBirthDate;
Date SGradDate;
Performance SPerformance;
public:
//Get/Accessor functions.
Name GetSName();
Address GetSAddress();
Date GetSBirthDate();
Date GetSGradDate();
Performance GetSPerformance();
void Report();
void SimpleReport();
//Set/Mutator Functions
//none, just use sub-class's setfunctions.
//constructors
Student();
};
Address Class's functions:
#ifndef Address
#define Address
#include "Address.h"
#endif
#ifndef string
#define string
#include <String.h>
#endif
//Get/Accessor functions
string Address :: GetLine1( ){ return Line1;}
string Address :: GetLine2(){return Line2;}
string Address :: GetCity(){return City;}
string Address :: GetState(){return State;}
int Address :: GetZip(){return Zip;}
//Set/Mutator functions
void Address :: SetLine1( string NewLine1 ){Line1 = NewLine1;}
void Address :: SetLine2( string NewLine2 ){Line2 = NewLine2;}
void Address :: SetCity( string NewCity ){City = NewCity;}
void Address :: SetState( string NewState ){State = NewState;}
void Address :: SetZip(int NewZip ){Zip=NewZip;}
void Address :: SetAddress(string NewLine1,string NewLine2,string NewCity,string NewState, int NewZip){SetLine1(NewLine1);SetLine2(NewLine2);SetCity(NewCity);SetState(NewState);SetZip(NewZip);}
//constructors
Address :: Address(){}
Date Class's functions:
#ifndef Date
#define Date
#include "Date.h"
#endif
//Get/Accessor functions
int Date :: GetYear(){return Year;}
int Date :: GetMonth(){return Month;}
int Date :: GetDay(){return Day;}
//Set/Mutator functions
void Date :: SetYear( int NewYear){Year = NewYear;}
void Date :: SetMonth(int NewMonth){Month = NewMonth;}
void Date :: SetDay(int NewDay){Day = NewDay;}
void Date :: SetDate(int NewDay,int NewMonth,int NewYear){SetDay(NewDay);SetMonth(NewMonth);SetYear(NewYear);}
//constructors
Date :: Date(){}
Name Class's functions:
#ifndef Name
#define Name
#include "Name.h"
#endif
#ifndef string
#define string
#include <String.h>
#endif
//Get/Accessor functions
string Name :: GetFirstName( return FirstName;){}
string Name :: GetLastName(){return LastName;}
//Set/Mutator functions
void Name :: SetFirstName( string NewFirstName ){FirstName = NewFirstName;}
void Name :: SetLastName( string NewLastName){LastName = NewLastName;}
void Name :: SetFullName(string NewFirstname,string NewLastName){SetFirstName(NewFirstName);SetLastName(NewLastName);}
//constructors
Name :: Name(){}
Performance Class's functions:
#ifndef Performance
#define Performance
#include "Performance.h"
#endif
//Get/Accessor functions
float Performance :: GetGPA(){return GPA;}
int Performance :: GetCredits(){return Credits;}
//Set/Mutator functions
void Performance :: SetGPA( float NewGPA ){GPA=NewGPA;}
void Performance :: SetCredits( int NewCredits){Credits=NewCredits;}
void Performance :: SetPerformance(float NewGPA,int NewCredits){SetGPA(NewGPA);SetCredits(NewCredits);}
//constructors
Performance :: Performance(){}
Student Class's functions:
#ifndef Student
#define Student
#include "Student.h"
#endif
#ifndef iostream
#define iostream
#include <iostream.h>
#endif
//Get/Accessor functions.
Name Student :: GetSName(){return SName;}
Address Student :: GetSAddress(){return SAddress;}
Date Student :: GetSBirthDate(){return SBirthDate;}
Date Student :: GetSGradDate(){return SGradDate;}
Performance GetSPerformance(){return SPerformance;}
//Utility Functions{}
void Student :: Report(){
cout <<"|--------------------------- ";
cout <<"Student's Name: ";
cout <<" First Name: "<<this.GetSName.GetFirstName()<<" ";
cout <<" Last Name: "<<this.GetSName.GetLastName()<<" /n";
cout <<"Student's Address: ";
cout <<" First Line: "<<this.GetSAddress.GetFirstLine() <<" ";
cout <<" Second Line: "<<this.GetSAddress.GetSecondLine()<<" ";
cout <<" City : "<<this.GetSAddress.GetCity() <<" ";
cout <<" State : "<<this.GetSAddress.GetState() <<" ";
cout <<" Zip : "<<this.GetSAddress.GetZip() <<" ";
cout <<"Student's BirthDate: ";
cout <<" Day : "<<this.GetSBirthDate.GetDay() <<" ";
cout <<" Month: "<<this.GetSBirthDate.GetMonth()<<" ";
cout <<" Year : "<<this.GetSBirthDate.GetYear() <<" ";
cout <<"Student's GradDate: ";
cout <<" Day : "<<this.GetSGradDate.GetDay() <<" ";
cout <<" Month: "<<this.GetSGradDate.GetMonth()<<" ";
cout <<" Year : "<<this.GetSGradDate.GetYear() <<" ";
cout <<"Student's Performance: "
cout <<" GPA : "<<this.GetSPerformance().GetGPA()<<" ";
cout <<" Credits: "<<this.GetSPerformance().GetCredits()<<" ";
cout <<"|--------------------------- ";
}
void Student :: SimpleReport(){
cout <<"|--------------------------- ";
cout <<"Student's Name: ";
cout <<" First Name: "<<this.GetSName.GetFirstName()<<" ";
cout <<" Last Name: "<<this.GetSName.GetLastName()<<" /n";
cout <<"|--------------------------- ";
}
//Set/Mutator Functions
//none, just use sub-class's setfunctions.
//constructors
Student :: Student(){}
Main cpp file:
#include <iostream.h>
#include <fstream>
#include <stdio.h>
#ifndef iostream
#define iostream
#include <iostream.h>
#endif
#ifndef string
#define string
#include <string.h>
#endif
#define STUDENTNUMBER 50 // Don't change with out also changing numerous things in TextGenerate Function.
#include "AddressFunctions.cpp"
#include "DateFunctions.cpp"
#include "NameFunctions.cpp"
#include "PerformanceFunctions.cpp"
#include "StudentFunctions.cpp"
//Function Declarations
void Print(*Student,int);
void SimplePrint(*Student,int);
void Alphabetize(*Student);
int TextGeneration();
//Function Definitions
void Print(*Student SArrayP,int Alphabetize){
if(Alphabetize != 1){
Alphabetize(SArrayP);
}
int i;
for(i=0; i<STUDENTNUMBER;i++){
SArrayP->Print();
SArray+=1;
}
}
void SimplePrint(*Student SArrayP,int Alphabetize){
if(Alphabetize != 0){
Alphabetize(SArrayP);
}
int i;
for(i=0; i<STUDENTNUMBER;i++){
SArrayP->SimplePrint();
SArray+=1;
}
}
void Alphabetize(*Student SArrayP){ // basic bubble sort, http://www.daniweb.com/software-development/cpp/code/216454 Helped alot. not 100% sure it'll work.
int i;//counter
int j;//counter
for(i=0;i<STUDENTNUMBER-1;i++){
for(j=0;j<STUDENTNUMBER-1-i;j++){
//combine first and last names into full names, and compare, swap if first is greater then second
if(strcmp((SArrayP->GetSName().GetFirstName())+=" " +=(SArrayP->GetSName().GetLastName()),((SArrayP+1)->GetSName().GetFirstName())+=" "+=((SArrayP+1)->GetSName().GetLastName()))>0){
swap(SArrayP[j],SArrayP[j+1])
}
}
}
}
int TextGeneration () {
srand(STUDENTNUMBER); // NOTE TO self: Make based on time when done debugging
ofstream Data;
Data.open ("Data.txt");
if(Data.is_open()){
int i; // counter
int j; // counter
//Name info
string new FirstName[STUDENTNUMBER];
string new LastName[STUDENTNUMBER];
//Address info
string new Line1[STUDENTNUMBER];
string new Line2[STUDENTNUMBER];
//variables to generate Unique full names
string new FirstNames1[5] = {"Allen","Bob","Charles","Dan","Edward"};
string new FirstNames2[5] = {"Adriene","Betty","Charlie","Danny","Edna"};
string new LastNames1[5] = {"Fnord","Gary","Howard","eyes","Joshua"};
string new LastNames2[5] = {"Fockers","Great","Henry","Its","Jones"};
string new FirstNames[2] = {FirstNames1,FirstNames2};
string new LastNames[2] = {LastNames1,LastNames2};
// Variables to generate random unique addresses
string new Lines1[5] = {"159 faternity st.","399 Dorm Blvd.","222 faternity st.", "777 Dorm Blvd", "82 Canal street");
string new Lines2[10] = {"Apartment A", "Apartment B", "Apartment C", "Apartment D", "Apartment E","Apartment F", "Apartment G", "Apartment H", "Apartment I"};
//Note to Self, Works?
for(i=0;i<STUDENTNUMBER;i++){
for(j=0; j<5; j++){
strCopy(FirstName[i],FirstNames[i>25][j]);//not 100% sure if this will work.
strCopy(LastName[i],LastNames[i>25][j + floor(i/5)-(i>25)*(floor(i/5)-6)- 4*((j+i/5)>5)]);
//^^Not 100% sure if this will work, changes to correct variables based on the value of other variables^^
}
}
// The above and below works?
for(i=0;i<STUDENTNUMBER;i++){
for(j=0; j<10; j++){
strCopy(Line1[i],Lines1[j]);// Not 100% sure if this will work
strCopy(Line2[i],Lines2[j + floor(i/10)-(i>25)*(floor(i/10)-11)- 4*((j+i/10)>10)]);
//^^This works2?, changes to correct variables based on the value of other variables
}
}
//The above works?
//deallocate unneeded variables
delete [] FirstNames1;
delete [] FirstNames2;
delete [] LastNames1;
delete [] LastNames2;
delete [] FirstNames;
delete [] LastNames;
for(i=0; i<STUDENTNUMBER;i++){
// name info
Data << FirstName[i] << " "; // first name
Data << LastName[i] << " "; // last name
// address info
Data << Line1[i] <" "; // line 1
Data << Line2[i] " "; // line 2
Data << "Indianapolis "; // city
Data << "IN "; // state
Data << "46168 "; // zip
// birthdate info
Data << rand()%28 + 1 << " "; //day
// ^^ No one is born between the 29th though 31st of any month, easier coding. ^^
Data << rand()%12 + 1 << " ";//month
Data << 2011 -(rand()%49 + 12)<< " ";//year
//graddate info
Data << rand()%28 + 1 << " ";//day
// ^^ No one Graduates between the 29th though 31st of any month, easier coding. ^^
Data << rand()%12 + 1 << " "; // month
Data << 2011 + (rand()%6+2)<< " "; // year
//performance info
Data << (rand()%16)/(float rand()%4)<<" "; //gpa
Data << (rand()%300)<< " "; //credits
// ^^ no one has 300 or more credits. ^^
}
//Deallocate rest of memory
delete [] FirstName;
delete [] LastName;
delete [] Line1;
delete [] line2;
Data.close();
} else {
cout << "Data File failed to open. ";
}
return 0;
}
int main(){
ifstream Data;
Data.open("Data.txt",ios::in);
Student new Students[STUDENTNUMBER];
string StudentInfo;
char Request;
int i = 0; // counter
int Alphabetize=0;
if(!Data.is_open()){ // create file if it is not already created.
Date.close("Data.txt");
TextGeneration();
Data.open("Data.txt");
}
if(Data.is_open()){
while ( Data.good() || i<STUDENTNUMBER){
//AssignNames
getline(Data,StudentInfo);
Students[i].GetSName().SetFirstName(StudentInfo);
getline(Data,StudentInfo);
Students[i].GetSName().SetLastName(StudentInfo);
//AssignAddress
getline(Data,StudentInfo);
Students[i].GetSAddress().SetLine1();
getline(Data,StudentInfo);
Students[i].GetSAddress().SetLine2(StudentInfo);
getline(Data,StudentInfo);
Students[i].GetSAddress().SetCity(StudentInfo);
getline(Data,StudentInfo);
Students[i].GetSAddress().SetState(StudentInfo);
getline(Data,StudentInfo);
Students[i].GetSAddress().SetLineZip(int(StudentInfo)); // not sure if type casting is neccassry or not, or if it returns the right value.
//AssignBirthDate
getline(Data,StudentInfo);
Students[i].GetSBirthDate().SetDay(int(StudentInfo));
getline(Data,StudentInfo);
Students[i].GetSBirthDate().SetMonth(int(StudentInfo));
getline(Data,StudentInfo);
Students[i].GetSBirthDate().SetYear(int(StudentInfo));
//AssignGradDate
getline(Data,StudentInfo);
Students[i].GetSGradDate().SetDay(int(StudentInfo));
getline(Data,StudentInfo);
Students[i].GetSGradDate().SetMonth(int(StudentInfo));
getline(Data,StudentInfo);
Students[i].GetSGradDate().SetYear(int(StudentInfo));
//AssignPerformance
getline(Data,StudentInfo);
Students[i].GetSPerformance().SetGPA(float(StudentInfo));
getline(Data,StudentInfo);
Students[i].GetSPerformance().SetCredits(int(StudentInfo));
i++
}
cout << "Would you like to print a list? Enter Y for yes, N for no please. ";
cin >> Request;
if(Request == 'Y' || request =='y'){
cout << " Would you like the list to be alphabatized? Enter Y for yes, N for no please. "
cin >> Request;
if(Request == 'Y' || request =='y'){
Alphabetize = 1;
}
cout << " Would you like the list Simple? Enter Y for yes, N for no please. "
cin >> Request;
if(Request == 'Y' || request =='y'){
SimplePrint(*Students,Alphabetize);
} else {
Print(*Students,Alphabetize);
}
}
cout << "Thank you and have a nice day. ";
} else {
cout << "File Could not Open.";
}
Data.close("Data.txt");
//deallocate memory
delete [] Students;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.