honestly I have stuck and I don't know where to start...There are 9 functions of this program but I will post only the first 2 since
are the most confused.. So.. The first function called Read_a_customer() the informations of customer : id, name, address
should be added array in the array in the correct place according to alphabetic order of customer name.. also it will check if the customer
is already added... my serious problem is that I can't save an array since the customer_Details must be a structure and instead of it will be added the id,name and address.. This is my first problem, the second one came is on the second function that called print_details_of_customer() I have finally create that, but for some reason if i will added 2 customers in a row, it's replaced the older record by the new one... Now, it's seems logical since may array isn't change position and just overwrite the previous data but I have check it again and again and the position is change, so I think something is going wrong with the structures and the correct declarations please check my code below because am serious desperate... Also check the point with the alphabetic order end let me know if am correct or not since I am not able to check it without complete the first part...!!
::NOTE:: Please ignore all the unuseless variable...
Thank you in advance!! Regards!!!
#include<iostream>
#include<cmath>
#include<string>
#include <stdio.h> //libraries for strcmp on unix/linux
#include <string.h> //libraries for strcmp on unix/linux
using namespace std;
int Read_a_customer();
int Print_details_of_a_customer();
int Return_the_number_of_the_customers();
struct CustomerDetails
{
char name[40];
char address[40];
char ID[40];
char title[40];
char author[40];
char ISBN[40]; //BookDetails STRUCT Variables
char status[40];
char date[40];
}date;
struct BookDetails
{
char title[40];
char author[40];
char ISBN[40]; //BookDetails STRUCT Variables
char status[40];
char date[40];
CustomerDetails T;
CustomerDetails F;
};
BookDetails failure_c;
BookDetails c;
BookDetails Array_c[10];
BookDetails failure_d;
BookDetails d;
BookDetails Array_d[10];
BookDetails input;
BookDetails output;
int number_customer = 0;
int const MAX = 100;
char temp[40];
int main()
{
char opt;
cout << "************************"<<endl;
cout << "Welcome to book store!!!"<<endl;
cout << "************************"<<endl;
cout <<"1. Read a customer."<<endl;
cout <<"4. Print details of customer."<<endl;
cout <<"Select one of the options: ";
cin >>opt;
switch (opt){
case '1': Read_a_customer();
break;
case '4': Print_details_of_a_customer();
break;
default: cout <<"You have enter error input..The program will exit..!!";
break;
}
return 0;
}
int Read_a_customer()
{
char opt;
cout<<endl;
for(int i=0;i<1;i++)
{
cin.ignore();
cout <<"\nPlease enter the customer ID: ";
cin.getline(Array_c[i+1].T.ID,40);
cout <<"Hit Enter..!!";
cin.ignore();
cout <<"\nPlease enter the customer name : ";
cin.getline(Array_c[i].T.name,40);
cout <<"Hit Enter..!!";
cin.ignore();
cout <<"\nPlease enter the customer address : ";
cin.getline(Array_c[i].T.address,40);
cout <<"Hit Enter..!!";
cout <<"Do you want to borrow one book?(y/n)?";
cin >> opt;
if (opt!='y' || opt!='Y')
{
cout<<endl;
cout <<"The customer with ID: "<< Array_c[i].T.ID << " was added"<<endl;
return main();
}
else
if (opt!='n' || opt!='N'){
cout <<"Error argument. you will now return into main menu..memory location reset. Nothing to save..!!!"<<endl;
Array_c[i] = failure_c;
Array_d[i] = failure_d;
return main();
}
else
cin.ignore();
cout << "\nPlease enter the title of the book: ";
cin.getline(d.F.title,40);
cout <<"Hit Enter..!!";
cin.ignore();
cout << "\nPlease enter the author of the book: ";
cin.getline(d.F.author,40);
cout <<"Hit Enter..!!";
cin.ignore();
cout << "\nPlease enter the ISBN of the book: ";
cin.getline(d.F.ISBN,40);
cout <<"Hit Enter..!!";
cin.ignore();
cout << "\nPlease enter the date that you borrow the book? (30-12-2012): ";
cin.getline(d.F.date,40);
strcpy(temp,Array_c[i].T.ID);
}
cout << "\nThe customer with ID: "<< c.T.ID << " was added. Customer also booked 1 book with ISBN: "<<d.F.ISBN<<" on "<< d.F.date<<" date";
cout <<"------"<<endl;
for(int i=0;i<3;i++)
if (strcmp(Array_c[i].T.name,Array_c[i+1].T.name)>0) //place the names with alphabetic order..
{
strcpy(temp,Array_c[i+1].T.name);
strcpy(Array_c[i+1].T.name,Array_c[i].T.name);
strcpy(Array_c[i+1].T.name,temp);
}
cout <<endl;
return main();
}
int Print_details_of_a_customer()
{
const int max=100;
cout << "***************************"<<endl;
cout << "Print Details Of A Customer"<<endl;
cout << "***************************"<<endl;
cin.ignore();
cout <<"Please enter the ID of a customer: ";
cin.getline(c.T.ID,40);
for(int i=0;i<max;i++)
{
if (strcmp(Array_c[i].T.ID,Array_c[i+1].T.ID)>0){
cout <<"The customer with ID: "<<c.T.ID<< " has the following details:"<<endl;
cout <<"Name: "<<Array_c[i].T.name<<endl;
cout <<"Address: "<<Array_c[i].T.address<<endl;
cout <<"---------"<<endl;
}
else
cout <<"There isn't any customer with this ID: "<<c.T.ID<<endl;}
return main();
}

New Topic/Question
Reply



MultiQuote





|