Alright, am getting somewhere with my code... Haven't shown you the file where things happen... Going to show you one function as yet, the rest later....
Menu.cpp
Code:
#include <iostream>
#include <algorithm>
#include <conio.h>
#include "Menu.h"
using namespace std;
Menu::Menu() {};
void Menu::titleDescription()
{
clrscr();
printf("\t\t\t\tÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»\n");
printf("\t\t\t\tº FLEET DETAILS º\n");
printf("\t\t\t\tÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ\n");
printf("\n\nThis program requests a file name in which a fleet of cars is saved.\n\n");
printf("A menu which allows the user an option to view the fleet, "
"\nsearch for a car, add new car, and update file is provided.\n\n");
pause();
clrscr();
programLimits();
}
// ---------------------------------------------------------------
// Implementing the user instructions function
void Menu::programLimits()
{
clrscr();
printf("\t\t\t\tÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»\n");
printf("\t\t\t\tº PROGRAM LIMITATIONS º\n");
printf("\t\t\t\tÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ\n");
printf("\n\nINPUTS:\n\n");
printf("FileName: FleetData.txt\n");
printf("Engine Capacity: (i.e.) 1.8L must be 1800\n");
printf("Dates: day, month, year\n");
printf("Tank capacity: Value 1 for filled, and 0 for unfilled\n\n");
pause();
}
void Menu::clrscr()
{
system("cls");
}
void Menu::pause()
{
puts("\n\n");
system("pause");
}
// ---------------------------------------------------------------
// Run will handle the user choice and run desired operation
void Menu::run()
{
bool again = true, found = false;
CarFleetIterator iterate=fleet.begin();
do
{
clrscr();
printf("\n \t\tÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»\n");
printf(" \t\tº FLEET DETAILS º\n");
printf(" \t\t\314ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ\271\n");
printf(" \t\tº Options º\n");
printf(" \t\tº º\n");
printf(" \t\tº1. Description of Program º\n");
printf(" \t\tº º\n");
printf(" \t\tº2. Read Fleet from File º\n");
printf(" \t\tº º\n");
printf(" \t\tº3. Display List of cars º\n");
printf(" \t\tº º\n");
printf(" \t\tº4. Search Car by Model & Make º\n");
printf(" \t\tº º\n");
printf(" \t\tº5. Add new car details º\n");
printf(" \t\tº º\n");
printf(" \t\tº6. Update Fleet File º\n");
printf(" \t\tº º\n");
printf(" \t\tº7. Edit Flee File º\n");
printf(" \t\tº º\n");
printf(" \t\tº8. Edit Flee File º\n");
printf(" \t\tÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ\n\n");
printf("\n\n\t\tPlease enter the NUMBER of your choice: ");
switch(_getch())
{
case DESCRIBE: titleDescription();
break;
case READF: readFleetFromFile();
pause();
break;
case DISPLAY: showFleetList(iterate, found);
pause();
break;
case SEARCHF: { // Search by make & model
puts("\n\n\t\tNot yet in operation!!");
if( (iterate = searchCarDetails(found)) == fleet.end() )
{
printf("\n\n\tTry searching again!");
}
else
if(found)
{
showFleetList(iterate, found); // Display found record
}
pause();
break;
}
case ADDCAR: AddNewCar();
pause();
break;
case UPDATEF: updateFleetFile(); // Save changes to text file
pause();
break;
case EDITF: EditFleet();
pause();
break;
case EXITP:
clrscr();
exit(1);
default: again = false;
break;
}
}
while (again);
}
Q. this line
Code:
CarFleetIterator iterate=fleet.begin();
doesn't seem to do the right job. After option 2 (READF), fleet gets initialized with all data from file... But, iterate doesn't seem to carry the data.... Cause the moment i press option 3 (DISPLAY), no proper data is passed... am i doing anything wrong?
here'sshowFLeetList()
Code:
// ---------------------------------------------------------------
// Implementing function to display fleet of cars
void Menu::showFleetList(CarFleetIterator iter, bool searched)
{
sortAlpha();
clrscr();
printf("\t\t\t\tÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»\n");
printf("\t\t\t\tº FLEET DETAILS º\n");
printf("\t\t\t\tÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ\n");
// **************** HEADINGS ***************
printf("\n\n%-17s%-12s%-13s%-12s%-8s\n\n", "Car Make/Model", "Year Model", "Engine Size",
"Return Date", "Fuel Tank" );
// **************** HEADINGS ***************
// Display one one record if fleet was searched
if (iter!=fleet.end() && searched)
{
iter->write(cout, true);
}
else
{
// Display fleet details to the screen
for(iter=fleet.begin(); iter!=fleet.end(); iter++)
{
iter->write(cout, true);
}
}
}