/* addStudents function with loop to add students one at a time in: none out: none */ void addStudents() { // declarations char firstName[32]; // store input first name char lastName[32]; // store input last name int completedCredits; // store input completed credits struct DATE enrollmentDate; // store input enrollment date struct STUDENT *s; // pointer to a student record // print header printf("Add Students\n============\n\n" "Start entering students. Leave first name blank to stop.\n\n"); // outer loop for entering another student do { // inner loop for repeating incorrect entry do { // print # entering printf("Student #%d\n", numStudents + 1); // get input from user strcpy(firstName, inputString("First name: ", 32)); if (strcmp(firstName, "") == 0) return; strcpy(lastName, inputString("Last name: ", 32)); if (strcmp(lastName, "") == 0) return; completedCredits = inputInteger("Completed credits: "); enrollmentDate = inputDate("Enrollment date (mm/dd/yyyy): "); // display input info back to user printf("\nFirst name: %s\n" "Last name: %s\n" "Completed credits: %d\n" "Enrollment date: %s\n", firstName, lastName, completedCredits, formatDate(enrollmentDate)); // repeat if info incorrect } while (!confirm("Info correct (y/n) ?")); // get pointer to new student s = &students[numStudents]; // put info into array at pointer strcpy(s->firstName, firstName); strcpy(s->lastName, lastName); s->completedCredits = completedCredits; s->enrollmentDate = enrollmentDate; // increment # of students numStudents ++; // loop if user wants to input another student } while (confirm("Add another student (y/n) ?")); }
/* editStudent edit an existing student, and display details as defaults for input in: pointer to a student to edit out: none */ void editStudent(struct STUDENT *s) { char firstName[32]; // store input first name char lastName[32]; // store input last name int completedCredits; // store input credits struct DATE enrollmentDate; // store input enrollment date // store an "empty date" to compare with entered date to indicate no change struct DATE noDate = {0}; do { // display what # student we're editing printf("\nEditing Student #%d\n", numStudents + 1); // input first name & update only if input not empty printf("First name: [%s] ", s->firstName); strcpy(firstName, inputString("", 32)); if (strcmp(firstName, "") == 0) strcpy(firstName, s->firstName); // input last name & update only if input not empty printf("Last name: [%s] ", s->lastName); strcpy(lastName, inputString("", 32)); if (strcmp(lastName, "") == 0) strcpy(lastName, s->lastName); // input completed credits & update only if input not empty printf("Completed credits: [%d] ", s->completedCredits); completedCredits = inputInteger(""); if (completedCredits == 0) completedCredits = s->completedCredits; // input enrollment date & update only if input not empty printf("Enrollment date (mm/dd/yyyy): [%s] ", formatDate(s->enrollmentDate)); enrollmentDate = inputDate(""); // since inputDate returns a struct DATE, we must check against an "empty" date if (compDates(enrollmentDate, noDate) == 0) enrollmentDate = s->enrollmentDate; // print details entered printf("\nFirst name: %s\n" "Last name: %s\n" "Completed credits: %d\n" "Enrollment date: %s\n", firstName, lastName, completedCredits, formatDate(enrollmentDate)); // confirm with user whether info correct, repeat input if not } while (!confirm("\nInfo correct (y/n) ?")); // store entered data back into the record pointed to by s strcpy(s->firstName, firstName); strcpy(s->lastName, lastName); s->completedCredits = completedCredits; s->enrollmentDate = enrollmentDate; }
void realestateManager::controller() { int i, index; string inputName; string inputAdress; Date inputBirthdate; Date inputEmploymentDate; int inputEmploeeId; string findByCity; string inStreet_adress; string inCityName; string inputSSN; int inputDay, inputMonth, inputYear; char choice=' '; char propertySort; bool validate=false; double inputArea; int inputPrice; int inYear; int inRoom; int inPrice; while(choice!='q'){ cout << "1 - Add an agent" << endl; cout << "2 - Add a property" << endl; cout << "3 - Rent or Sold a Property" << endl; cout << "4 - Find properties in a city" << endl; cout << "5 - Find properties by agent" << endl; cout << "6 - Display agents" << endl; cout << "7 - Display available properties" << endl; cout << "8 - Display sold or rented properties" << endl; cout << "q - to quit" << endl; cin >> choice; switch(choice){ case '1'://add an agent cout << "Enter the agent name : "; cin >> inputName; cout << "Enter the address : "; cin >>inputAdress; cout << "Enter his birth date (day, month year) : " << endl; cin >> inputDay; cin >> inputMonth; cin >> inputYear; inputBirthdate.setDay(inputDay); inputBirthdate.setMonth(inputMonth); inputBirthdate.setYear(inputYear); cout << "Enter his employment date (day, month year) : " << endl; cin >> inputDay; cin >> inputMonth; cin >> inputYear; inputEmploymentDate.setDay(inputDay); inputEmploymentDate.setMonth(inputMonth); inputEmploymentDate.setYear(inputYear); cout << "Enter the employee id : "; cin >> inputEmploeeId; validate=this->insertAgent(new RealEstateAgent(inputName, inputAdress, inputBirthdate, inputEmploymentDate,inputEmploeeId)); break; case '2'://add a property cout << "For a LandSale enter L, for a house sale enter H and for a house rental enter h :"; cin >> propertySort; for(i=0;i<this->listingsize;i++){ if(this->propertyListingArray[i]==NULL){ for(i=0;i<max_number_of_agents;i++){ if(this->agentRecordsArray[i]!=NULL) { cout <<"index"<< i << endl; this->agentRecordsArray[i]->print(); cout << endl; } } do { cout << "Enter the agent's index you want : "; cin >> index; }while(this->agentRecordsArray[index]==NULL); cout << "Enter the address : "; cin >> inStreet_adress; cout << "Enter the city name : "; cin >> inCityName; cout << "Enter the listing date (day, month year) : " << endl; cin >> inputDay; cin >> inputMonth; cin >> inputYear; Date inputDate(inputDay,inputMonth,inputYear); cout << "Enter the landlord's name : "; cin >>inputName; cout << "enter the landlord's address : "; cin >> inputAdress; cout << "Enter his SSN : "; cin >> inputSSN; cout << "Enter his birth date (day, month year) : " << endl; cin >> inputDay; cin >> inputMonth; cin >> inputYear; inputBirthdate.setDay(inputDay); inputBirthdate.setMonth(inputMonth); inputBirthdate.setYear(inputYear); Customer inputCustomer(inputName,inputAdress, inputBirthdate,inputSSN); switch(propertySort){ case 'L': cout << "Enter the area : "; cin >> inputArea; cout << "Enter the price : "; cin >> inputPrice; //LandSale * inputLandSale = new LandSale(inStreet_adress, inCityName, inputCustomer, *(this->agentRecordsArray[index]),inputDate,inputArea,inputPrice); this->insertProperty(new LandSale(inStreet_adress, inCityName, inputCustomer, *(this->agentRecordsArray[index]),inputDate,inputArea,inputPrice)); break; case 'H': cout << "Enter the year of building : "; cin >> inYear; cout << "Enter the number of room : "; cin >> inRoom; cout << "Enter the price : "; cin >> inPrice; //Property * inputProperty = new HouseSale(inStreet_adress, inCityName, new Customer(inputName,inputAdress, inputBirthdate,inputSSN),this->agentRecordsArray[index], new Date(inputDay,inputMonth,inputYear), inYear,inRoom,inPrice); this->insertProperty(new HouseSale(inStreet_adress, inCityName, inputCustomer,*(this->agentRecordsArray[index]),inputDate, inYear,inRoom,inPrice)); break; case 'h': cout << "Enter the year of building : "; cin >> inYear; cout << "Enter the number of room : "; cin >> inRoom; cout << "Enter the monthly price : "; cin >> inPrice; //Property * inputProperty = new HouseRental(inStreet_adress, inCityName, new Customer(inputName,inputAdress, inputBirthdate,inputSSN),this->agentRecordsArray[index], new Date(inputDay,inputMonth,inputYear), inYear,inRoom,inPrice); this->insertProperty(new HouseRental(inStreet_adress, inCityName,inputCustomer,*(this->agentRecordsArray[index]),inputDate, inYear,inRoom,inPrice)); break; } } i = listingsize; } break; case '3'://rent or sold a property cout << "Enter the customer's name : "; cin >>inputName; cout << "enter the customer's address : "; cin >> inputAdress; cout << "Enter his SSN : "; cin >> inputSSN; cout << "Enter his birth date (firts day, month year) : " << endl; cin >> inputDay; cin >> inputMonth; cin >> inputYear; inputBirthdate.setDay(inputDay); inputBirthdate.setMonth(inputMonth); inputBirthdate.setYear(inputYear); //Customer * buyer=new Customer(inputName,inputAdress, inputBirthdate,inputSSN); for(i=0;i<this->listingsize;i++){ if(this->propertyListingArray[i]!=NULL) { cout <<"index "<< i << endl; this->propertyListingArray[i]->print(); cout << endl; } } do { cout << "Which property you want (enter index) : "; cin >> i; }while(this->propertyListingArray[i]==NULL); this->propertysoldrented(this->propertyListingArray[i],new Customer(inputName,inputAdress, inputBirthdate,inputSSN)); break; case '4'://find a property in a city cout << "Enter the city name :"; cin >> findByCity; this->findPropertiesCity(findByCity); break; case '5'://find property by agent for(i=0;i<max_number_of_agents;i++){ if(this->agentRecordsArray[i]!=NULL) { cout <<"index "<< i << endl; this->agentRecordsArray[i]->print(); cout << endl; } } do{ cout << "Enter the agent's index you want : "; cin >> i; }while(this->agentRecordsArray[i]==NULL); this->findPropertiesAgent(this->agentRecordsArray[i]); break; case '6': for(i=0;i<max_number_of_agents;i++){ if(this->agentRecordsArray[i]!=NULL) { cout <<"Agent "<< i << endl; this->agentRecordsArray[i]->print(); cout << endl << endl; } } break; case '7': for(i=0;i<this->listingsize;i++){ if(this->propertyListingArray[i]!=NULL) { cout <<"Property "<< i << endl; this->propertyListingArray[i]->print(); cout << endl << endl; } } break; case '8': for(i=0;i<this->archivesize;i++){ if(this->archiveRecordsArray[i]!=NULL) { cout << "Property " << i << endl; this->archiveRecordsArray[i]->print(); cout << endl << endl; } } break; case 'q'://quit break; default: cout << "Please enter a correct choice : " << endl; cout << "1 - Add an agent" << endl; cout << "2 - Add a property" << endl; cout << "3 - Rent or Sold a Property" << endl; cout << "4 - Find properties in a city" << endl; cout << "5 - Find properties by agent" << endl; cout << "q - to quit" << endl; cin >> choice; break; } } }