// array.cpp #include #include using namespace std; #include "array.h" // array function // constructor array::array() { //read_students(); char student_command[20]; // student array variables char student_name[20] = " "; char student_phone[20] = " "; char student_email[20] = " "; char student_address1[20] = " "; char student_address2[20] = " "; char student_city[20] = " "; char student_state[20] = " "; char student_zip[20] = " "; char student_other[150] = " "; // item array variables char itemName[20] = " "; char media[20] = " "; char author[20] = " "; char by[20] = " "; char amount[20] = " "; char avail[20] = " "; // input stream variables ifstream infile; ifstream in; // opens both input files infile.open("students.data"); in.open("items.data"); // student and item array index counter stu_count = 0; item_count = 0; // reads input from item.txt while(in) { in.getline(student_command, 20, '\n'); if (student_command[1] == 'I') in.getline(itemName, 20, '\n'); else if (student_command[1] == 'M') in.getline(media, 20, '\n'); else if (student_command[1] == 'b') in.getline(author, 20, '\n'); else if (student_command[1] == 'O') { in.getline(by, 20, '\n'); } else if (student_command[1] == 'P') in.getline(amount, 20, '\n'); else if (student_command[1] == 'A') in.getline(avail, 20, '\n'); else if (student_command[1] == '@') { // creates an item object item new_item(itemName, media, author, by, amount, avail); // stores object in item array itemArray[item_count] = new_item; item_count++; strcpy(itemName, " "); strcpy(media, " "); strcpy(author, " "); strcpy(by, " "); strcpy(amount, " "); strcpy(avail, " "); in.getline(student_command, 20, '\n'); } }// {end while loop} // reads input from student.txt while(infile) { infile.getline(student_command, 20, '\n'); if (student_command[1] == 'N') { infile.getline(student_name, 20, '\n'); } else if (student_command[1] == 'P') { infile.getline(student_phone, 20, '\n'); } else if (student_command[1] == 'E') { infile.getline(student_email, 20, '\n'); } else if (student_command[1] == 'A' && student_command[14] == '1') { infile.getline(student_address1, 20, '\n'); } else if (student_command[1] == 'A' && student_command[14] == '2') { infile.getline(student_address2, 20, '\n'); } else if (student_command[1] == 'C') { infile.getline(student_city, 20, '\n'); } else if (student_command[1] == 'S') { infile.getline(student_state, 20, '\n'); } else if (student_command[1] == 'Z') { infile.getline(student_zip, 20, '\n'); } else if (student_command[1] == 'O') { infile.getline(student_other, 150, '\n'); } else if (student_command[1] == '@') { // creates a student object student new_student(student_name, student_phone, student_email, student_address1, student_address2, student_city, student_state, student_zip, student_other); // adds object to array studentArray[stu_count] = new_student; stu_count++; strcpy(student_name, " "); strcpy(student_phone, " "); strcpy(student_email, " "); strcpy(student_address1, " "); strcpy(student_address2, " "); strcpy(student_city, " "); strcpy(student_state, " "); strcpy(student_zip, " "); strcpy(student_other, " "); infile.getline(student_command, 20, '\n'); } }// {end while loop} // closing input files infile.close(); in.close(); }; // {end constructor} // destructor function array::~array() { }; // {end destructor} void array::read_students() { char student_command[20]; char student_name[20] = " "; char student_phone[20] = " "; char student_email[20] = " "; char student_address1[20] = " "; char student_address2[20] = " "; char student_city[20] = " "; char student_state[20] = " "; char student_zip[20] = " "; char student_other[100] = " "; ifstream first; first.open("students.txt"); stu_count = 0; while(!first.eof()) { first.getline(student_command, 20, '\n'); cout << student_command << endl; if (student_command[1] == 'N') { first.getline(student_name, 20, '\n'); cout << student_name << endl; } else if (student_command[1] == 'P') { first.getline(student_phone, 20, '\n'); cout << student_phone << endl; } else if (student_command[1] == 'E') { first.getline(student_email, 20, '\n'); cout << student_email << endl; } else if (student_command[1] == 'A' && student_command[14] == '1') { first.getline(student_address1, 20, '\n'); cout << student_address1 << endl; } else if (student_command[1] == 'A' && student_command[14] == '2') { first.getline(student_address2, 20, '\n'); cout << student_address2 << endl; } else if (student_command[1] == 'C') { first.getline(student_city, 20, '\n'); cout << student_city << endl; } else if (student_command[1] == 'S') { first.getline(student_state, 20, '\n'); cout << student_state << endl; } else if (student_command[1] == 'Z') { first.getline(student_zip, 20, '\n'); cout << student_zip << endl; } else if (student_command[1] == 'O') { first.getline(student_other, 100, '\n'); cout << student_other << endl; } else if (student_command[1] == '@') { // creates a student object student new_student(student_name, student_phone, student_email, student_address1, student_address2, student_city, student_state, student_zip, student_other); // adds object to array studentArray[stu_count] = new_student; stu_count++; first.getline(student_command, 20, '\n'); cout << endl; } }// {end while loop} first.close(); }; // print student function // prints to file all students in the order they were added void array::print_students(ofstream& out) { char *temp; for (int i=0; i0) i++; temp = studentArray[i].return_email(); // {end of do while loop} }while(strcmp(temp, e_mail) != 0);*/ while(i < stu_count) { temp = studentArray[i].return_email(); if (strcmp(temp, e_mail) == 0) break; i++; } if (i == stu_count) out << e_mail << " not found." << endl; else { temp = studentArray[i].return_name(); if(strcmp(temp, " ") != 0) { out << "Name:" << endl; out << " " << studentArray[i].return_name() << endl; } temp = studentArray[i].return_phone(); if(strcmp(temp, " ") != 0) { out << "Phone Number:" << endl; out << " " << studentArray[i].return_phone() << endl; } temp = studentArray[i].return_email(); if(strcmp(temp, " ") != 0) { out << "Email:" << endl; out << " " << studentArray[i].return_email() << endl; } temp = studentArray[i].return_add1(); if(strcmp(temp, " ") != 0) { out << "Address:" << endl; out << studentArray[i].return_add1() << endl; sentinel = 1; } temp = studentArray[i].return_add2(); if(strcmp(temp, " ") != 0) { if (sentinel == 0) out << "Address:" << endl; out << studentArray[i].return_add2() << endl; sentinel = 1; } temp = studentArray[i].return_city(); if(strcmp(temp, " ") != 0) { if (sentinel == 0) out << "Address:" << endl; out << studentArray[i].return_city() << ", "; sentinel = 1; } temp = studentArray[i].return_state(); if(strcmp(temp, " ") != 0) { if (sentinel == 0) out << "Address:" << endl; out << studentArray[i].return_state() << " "; sentinel = 1; } temp = studentArray[i].return_zip(); if(strcmp(temp, " ") != 0) { if (sentinel == 0) out << "Address:" << endl; out << studentArray[i].return_zip() << endl; } temp = studentArray[i].return_other(); if(strcmp(temp, " ") != 0) { out << "Other:" << endl; out << " " << studentArray[i].return_other() << endl; } out << endl; int x = 0; do { temp = itemArray[x].return_owner(); if(strcmp(temp, e_mail) == 0) { temp = itemArray[x].return_item(); if (strcmp(temp, " ") != 0) { out << "Item:" << endl; out << " " << temp << endl; } temp = itemArray[x].return_media(); if (strcmp(temp, " ") != 0) { out << "Media Type:" << endl; out << " " << temp << endl; } temp = itemArray[x].return_author(); if (strcmp(temp, " ") != 0) { out << "by:" << endl; out << " " << temp << endl; } temp = itemArray[x].return_price(); if (strcmp(temp, " ") != 0) { out << "Price:" << endl; out << " " << temp << endl; } temp = itemArray[x].return_avail(); if (strcmp(temp, " ") != 0) { out << "Availability:" << endl; out << " " << temp << endl; } out << endl; } x++; // {end of do while loop} }while(x < item_count); } }; // {end of print email function} // delete_entry function // finds all entries with given email address // and deletes both the student's info and associated items // in: email address char array bool array::delete_entry(char e_mail[]) { bool success = true; int i = 0; char *temp; while (i <= stu_count) { if (i == stu_count) { success = false; return(success); } temp = studentArray[i].return_email(); if (strcmp(temp, e_mail) == 0) break; i++; } // {end while loop} // deleting student record studentArray[i].clear(); for(int x=0; x