1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
|
#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] << "\n"; // first name
Data << LastName[i] << "\n"; // last name
// address info
Data << Line1[i] <" \n"; // line 1
Data << Line2[i] " \n"; // line 2
Data << "Indianapolis \n"; // city
Data << "IN \n"; // state
Data << "46168 \n"; // zip
// birthdate info
Data << rand()%28 + 1 << " \n"; //day
// ^^ No one is born between the 29th though 31st of any month, easier coding. ^^
Data << rand()%12 + 1 << " \n";//month
Data << 2011 -(rand()%49 + 12)<< "\n";//year
//graddate info
Data << rand()%28 + 1 << " \n";//day
// ^^ No one Graduates between the 29th though 31st of any month, easier coding. ^^
Data << rand()%12 + 1 << " \n"; // month
Data << 2011 + (rand()%6+2)<< " \n"; // year
//performance info
Data << (rand()%16)/(float rand()%4)<<" \n"; //gpa
Data << (rand()%300)<< " \n"; //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. \n";
}
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. \n";
cin >> Request;
if(Request == 'Y' || request =='y'){
cout << " Would you like the list to be alphabatized? Enter Y for yes, N for no please. \n"
cin >> Request;
if(Request == 'Y' || request =='y'){
Alphabetize = 1;
}
cout << " Would you like the list Simple? Enter Y for yes, N for no please. \n"
cin >> Request;
if(Request == 'Y' || request =='y'){
SimplePrint(*Students,Alphabetize);
} else {
Print(*Students,Alphabetize);
}
}
cout << "Thank you and have a nice day. \n";
} else {
cout << "File Could not Open.";
}
Data.close("Data.txt");
//deallocate memory
delete [] Students;
return 0;
}
|