a little help needed with my functions which im using to save a structured array. i have the function prototypes at the begining, which are giving me the first set of error messages.
i have put the functions at the bottom of the source file.
if anybody could give me the answer as to why it wont compile will be perfect. thanks,
Code:
#include <cstdlib>
#include <iostream>
#include <string>
#include <windows.h>
#include <stdio.h>
#include <fstream>
using namespace std;
struct Part //decleration of data structure for parts
{
int Part_ID;
char Description[15];
char Condition[10];
float Guide_Price;
int Origin_Vehicle_ID;
bool Present;
};
struct Vehicles //decleration of data structure for vehicles
{
int Vehicle_ID;
char Model[10];
char Colour[10];
int Mileage;
float Purchase_Price;
Part Parts[323];
};
struct Order //decleration of data structure for orders
{
int Order_ID;
int Customer_ID;
int Part_ID[10];
bool Paid;
};
struct Customers //decleration of data structure for customers details
{
int Customer_ID;
char Name[15];
char Address[15];
char Addresstwo[15];
char Town[10];
char County[10];
char Postcode[6];
char TelNo[12];
Order Orders[10];
};
int Program;
int Number_of_Vehicles = 0, Number_of_Customers = 0;
Customers Customer[10]; //arrayed data structures
Vehicles Vehicle[10];
int Show_Main_Menu(); //function prototypes
void Get_Order_Quote();
void Input_New_Customer();
void Check_Order_Details();
void Look_Up_Customer();
void Place_New_Order();
void Enter_New_Vehicle();
int SaveVehicles(Vehicle*, int);
int SaveCustomers(Customers*, int);
int MasterFile(int, int);
int main(int argc, char *argv[])
{
while(Program != 8)
{//while 'program'
switch (Show_Main_Menu())
{ //switch
//------------------------------------------------------------------------------
case 1:
{//case 1
Get_Order_Quote();
break;
}//case 1
//------------------------------------------------------------------------------
case 2:
{//case 2
Place_New_Order();
break;
}//case 2
//------------------------------------------------------------------------------
case 3:
{//case 3
Check_Order_Details();
break;
}//case 3
//------------------------------------------------------------------------------
case 4:
{//case 4
Input_New_Customer();
SaveCustomers();
break;
}//case 4
//------------------------------------------------------------------------------
case 5:
{//case 5
cout << "Print Bills" << endl;
break;
}//case 5
//------------------------------------------------------------------------------
case 6:
{//case 6
Look_Up_Customer();
break;
}//case 6
//------------------------------------------------------------------------------
case 7:
{//case 7
Enter_New_Vehicle();
SaveVehicles(Number_of_Vehicles);
break;
}//case 7
//------------------------------------------------------------------------------
case 8:
{//case 7
return 0;
break;
}//case 7
//------------------------------------------------------------------------------
}//switch statement
}//while 'program'
}//int main
//XXXXXXXXXXXXXXXXXXXXXXX FUNCTIONS XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
int Show_Main_Menu() //OK and tested!
{
int Main_Menu_Option;
system("cls");
cout << " ** Main Menu **" << endl;
cout << endl;
cout << "1) Order Quote" << endl;
cout << "2) New Order" << endl;
cout << "3) Check Order Details" << endl;
cout << "4) Enter New Customer" << endl;
cout << "5) Print Bills" << endl;
cout << "6) Look Up Customer" << endl;
cout << "7) Enter New Vehicle" << endl;
cout << "8) Quit Program" << endl;
cout << endl;
cout << "Option : ";
cin >> Main_Menu_Option;
system("cls");
return Main_Menu_Option;
};
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
void Input_New_Customer() //looks OK but not tested!
{
system("cls");
cout << "Enter New Customer" << endl;
cout << endl;
cout << "Name : ";
cin >> Customer[Number_of_Customers].Name;
cout << "Address : ";
cin >> Customer[Number_of_Customers].Address;
cout << "Address line two : ";
cin >> Customer[Number_of_Customers].Addresstwo;
cout << "Town : ";
cin >> Customer[Number_of_Customers].Town;
cout << "County : ";
cin >> Customer[Number_of_Customers].County;
cout << "Postcode : ";
cin >> Customer[Number_of_Customers].Postcode;
cout << "Customer ID : " << Number_of_Customers << endl;
cout << endl;
Number_of_Customers ++;
system("PAUSE");
system("cls");
};
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
void Check_Order_Details() //Looks OK but not tested!
{
int Order_ID, i, x, y;
system("cls");
cout << "Check Order Details" << endl;
cout << endl;
cout << "Enter Order ID : ";
cin >> Order_ID;
for(i=0; i<Number_of_Customers; i++) //loops through all customers
{
for(x=0; x<10; x++) //loops through all orders that customer has
{
if(Customer[i].Orders[x].Order_ID == Order_ID) //checks each order for a match on Order_ID
{//if statement
cout << Customer[i].Orders[x].Part_ID << endl; //displays details of the order
cout << Customer[i].Orders[x].Paid << endl;
cout << Customer[i].Orders[x].Customer_ID << endl;
for(y=0; y<Number_of_Customers; y++) //loops through all customers
{//for loop
if(Customer[y].Customer_ID == Customer[i].Orders[x].Customer_ID) //checks for match on Customers ID
{//if statement
cout << Customer[y].Name << endl; //displays name of customer above
}//if statement
}//for loop
}//if statement
}//for loop x
}//for loop i
cout << endl;
system("PAUSE");
};//function
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
void Get_Order_Quote() //OK but not tested!
{
int ID, Part_ID, i;
cout << "Order Quote" << endl;
cout << endl;
cout << "Input Part ID : ";
cin >> ID;
for(i=0; i<Number_of_Vehicles; i++) //loops through all vehicles catalogued
{//for loop ID
for(ID=0; ID<323; ID++) //loops through parts available on vehicle
{ //for loop i
if(ID == Vehicle[i].Parts[ID].Part_ID && Vehicle[i].Parts[ID].Present == 1 )//checks for a match on the parts ID
{//if
cout << Vehicle[i].Parts[ID].Part_ID << " is on Vehicle " << i << endl;
cout << Vehicle[i].Parts[ID].Description << " is " << Vehicle[i].Parts[ID].Guide_Price << endl;
}//if
}//for loop i
}//for loop
system("PAUSE");
};
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
void Place_New_Order()
{//func place_new_order
int Sub_Opt, Customer_ID, Part_ID;
int x, i;
cout << "New Order" << endl;
cout << endl;
cout << "1) Create New Customer" << endl;
cout << "2) Enter Customer ID" << endl;
cout << endl;
cout << "Option : ";
cin >> Sub_Opt;
switch(Sub_Opt)
{//switch subopt
//------------------------------------------------------------------------------
case 1:
{//case 1
Input_New_Customer();
SaveCustomers(Number_of_Customers);
break;
}//case 1
//------------------------------------------------------------------------------
case 2:
{//case 2
cout << "Customer ID : ";
cin >> Customer_ID;
cout << "Enter Part ID";
cin >> Part_ID;
for(i=0; i<Number_of_Vehicles; i++)//loops through all vehicles
{//for loop i
for(x=0; x<323; x++)//loops through all parts in specific vehicle
{//for loop x
if(Part_ID == Vehicle[i].Parts[x].Part_ID && Vehicle[i].Parts[x].Present == 1)//test for a match of part_id and that its present on vehicle
{//if statement
cout << Vehicle[i].Parts[x].Description << endl;
}//if statement
}//for loop x
}//for loop i
break;
}//case 2
//------------------------------------------------------------------------------
}//switch subopt
};//func place_new_order
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
void Look_Up_Customer() //OK and tested!
{
int ID;
cout << "Look up Customer" << endl;
cout << endl;
cout << "Please Enter Customer ID : ";
cin >> ID;
cout << "Name : " << Customer[ID].Name << endl;
cout << "Address : " << Customer[ID].Address << endl;
cout << " " << Customer[ID].Addresstwo << endl;
cout << " " << Customer[ID].Town << endl;;
cout << " " << Customer[ID].County << endl;
cout << " " << Customer[ID].Postcode << endl;
cout << "Telephone : " << Customer[ID].TelNo << endl;
system("PAUSE");
};
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
void Enter_New_Vehicle()
{//func Enter_New_Vehicle
int i, Part_ID;
cout << "Enter New Vehicle For Breaking" << endl;
cout << endl;
cout << "Model : ";
cin >> Vehicle[Number_of_Vehicles].Model;
cout << "Colour : ";
cin >> Vehicle[Number_of_Vehicles].Colour;
cout << "Mileage : ";
cin >> Vehicle[Number_of_Vehicles].Mileage;
cout << "Purchase Price : ";
cin >> Vehicle[Number_of_Vehicles].Purchase_Price;
cout << "Vehicle ID : " << Number_of_Vehicles << endl;
for(i=0; i<323; i++)
{
Vehicle[Number_of_Vehicles].Parts[i].Present = 1;
}
cout << "What Parts Are Missing or Damaged?" << endl;
cout << endl;
cout << "Enter 8 When Finished" << endl;
cout << endl;
cout << "Part ID('s) Which are Missing or Damaged : ";
cin >> Part_ID;
if(Part_ID != 8)
{//if statment
for(i=0; i<323; i++)
{//for loop
if(Vehicle[Number_of_Vehicles].Parts[i].Part_ID == Part_ID)
{//if statment
Vehicle[Number_of_Vehicles].Parts[i].Present == 0;
}//if statement
}//for loop
}//if statement
Number_of_Vehicles++;
};//func Enter_New_Vehicle
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
int SaveVehicles(Vehicle* Vehicles, int Number_of_Vehicles)
{
int i, x;
ofstream Vehicle_File("d:\\Vehicle.dat");
for(x=0; x<Number_of_Vehicles; x++)
{//for loop x
Vehicle_File << Vehicle[Number_of_Vehicles].Vehicle_ID << endl;
Vehicle_File << Vehicle[Number_of_Vehicles].Model << endl;
Vehicle_File << Vehicle[Number_of_Vehicles].Mileage << endl;
Vehicle_File << Vehicle[Number_of_Vehicles].Colour << endl;
Vehicle_File << Vehicle[Number_of_Vehicles].Purchase_Price << endl;
for(i=0; i<323; i++)
{//for loop i
Vehicle_File << Vehicle[Number_of_Vehicles].Parts[i].Part_ID << endl;
Vehicle_File << Vehicle[Number_of_Vehicles].Parts[i].Description << endl;
Vehicle_File << Vehicle[Number_of_Vehicles].Parts[i].Condition << endl;
Vehicle_File << Vehicle[Number_of_Vehicles].Parts[i].Guide_Price << endl;
Vehicle_File << Vehicle[Number_of_Vehicles].Parts[i].Origin_Vehicle_ID;
Vehicle_File << Vehicle[Number_of_Vehicles].Parts[i].Present << endl;
}//for loop i
}//for loop x
Vehicle_File.close();
return 0;
};
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
int SaveCustomers(Customers* Customer, int Number_of_Customers)
{
int i, x;
ofstream Customers_File("d:\\Customers.dat");
for(x=0; x<Number_of_Customers; x++)
{//for loop x
Customers_File << Customers[Number_of_Customers].Customer_ID << endl;
Customers_File << Customers[Number_of_Customers].Name << endl;
Customers_File << Customers[Number_of_Customers].Address << endl;
Customers_File << Customers[Number_of_Customers].Addresstwo << endl;
Customers_File << Customers[Number_of_Customers].Town << endl;
Customers_File << Customers[Number_of_Customers].County << endl;
Customers_File << Customers[Number_of_Customers].Postcode << endl;
Customers_File << Customers[Number_of_Customers].TelNo << endl;
for(i=0; i<10; i++)
{//for loop i
Customers_File << Customers[Number_of_Customers].Orders[i].Order_ID << endl;
Customers_File << Customers[Number_of_Customers].Orders[i].Customer_ID << endl;
Customers_File << Customers[Number_of_Customers].Orders[i].Part_ID << endl;
Customers_File << Customers[Number_of_Customers].Orders[i].Paid << endl;
}//for loop i
}//for loop x
Customers_File.close();
return 0;
};
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
int MasterFile(int Number_of_Vehicles, int Number_of_Customers)
{
ofstream Master_File("d:\\Master.dat");
Master_File << Number_of_Vehicles << endl;
Master_File << Number_of_Customers << endl;
Master_File.close();
return 0;
};