Sunteți pe pagina 1din 4

#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)
{
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();
}

S-ar putea să vă placă și