#include<iostream.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
#include<iomanip.h>
void Insert_Sort(char [][10],long [],int&);
void Display(char [][10],long [],int&);
void SearchC(char [][10],int&);
void SearchP(long [],char [][10],int&);
void Delete(char [][10],long [],int&);
void Exit(int&);
void main()
{
system("color 4f");
const int Max=30;
char Car[Max][10];
long Price[Max];
int ch,num=0,search;
for(int a=0;a<Max;a++)
{
Price[a]=0;
for(int b=0;b<10;b++)
Car[a]='\0';
}//this loop is to initialize the value of both cars & prices Arrayes
do
{
cout<<endl<<setw(47)<<" )*(WELCOME)*(\n"
<<setw(45)<<" /_______/|\n"
<<setw(51)<<" ____| | ||______\n"
<<setw(52)<<"/_____|___|___|/_____/|\n"
<<setw(52)<<"| ___' |' ___ C| |\n"
<<setw(51)<<"|__( @ )__|__( @ )__|/\n"
<<setw(46)<<" '-' '-'\n"
<<setw(71)<<" ---------------------------(^_^)-----------------------------\n"
<<setw(72)<<"| This program helps you as an owner for a car company |\n"
<<setw(72)<<"| It gives you many usefull choices to organize your business |\n"
<<setw(72)<<"| You could choose the service you need from the list below |\n"
<<setw(71)<<" -------------------------------------------------------------\n"
<<setw(55)<<" ___ ___ \n"
<<setw(56)<<" _|_1_|_ _|_2_|_\n"
<<setw(57)<<"|_o_|_o_| |_o_|_o_|\n"
<<setw(56)<<" INSERT DISPLAY\n"
<<setw(55)<<" ___ ___ \n"
<<setw(56)<<" _|_3_|_ _|_4_|_\n"
<<setw(57)<<"|_o_|_o_| |_o_|_o_|\n"
<<setw(56)<<" SEARCH DELETE\n"
<<setw(43)<<" ___\n"
<<setw(45)<<" _|_5_|_\n"
<<setw(46)<<"|_o_|_o_|\n"
<<setw(43)<<" EXIT\n";
cin>>ch;
if(ch==1)
Insert_Sort(Car,Price,num);
else if(ch==2)
Display(Car,Price,num);
else if(ch==3)
{
if(num>0)
{
cout<<setw(50)<<"You chose (SEARCH)\n"
<<setw(57)<<"There are two kinds of search :\n"
<<setw(72)<<"1* You could search for a certain car by entering it's name.\n"
<<setw(71)<<"2* You could enter a price & a list of cars with this price\n"
<<setw(36)<<"or less will appeare.\n"
<<endl<<setw(57)<<"Enter your choice , please : ";
cin>>search;
if(search==1)
SearchC(Car,num);
else
SearchP(Price,Car,num);
}
else//this massage will appeares if the company was empty
cout<<setw(60)<<" -----------------(^_^)-----------------\n"
<<setw(61)<<"| Sorry there is no cars in the company |\n"
<<setw(61)<<"| try to insert cars first please |\n"
<<setw(60)<<" ---------------------------------------\n";
}
else if(ch==4)
Delete(Car,Price,num);
else
Exit(ch);
cout<<endl;
getch();
system("cls");
}while(ch!=6);
}//end main
void Insert_Sort(char C[30][10],long P[30],int &n)
{
char xC[10],ans[4];
long xP;
if(n<29)
{
cout<<setw (75)<<"You chose (INSERT) which allowes you to enter cars to the company..\n"
<<setw (57)<<"The company can acceptes 30 cars\n"
<<setw (67)<<"so please make sure you don't get over this limit..\n\n";
do//this do/while loop will receive the cars names & prices from the user
{
cout<<setw (45)<<"Enter the name of car no. "<<n+1<<" , please : ";
cin>>C[n];
cout<<setw (50)<<"Enter it's price , please : ";
cin>>P[n];
cout<<endl<<setw (53)<<"Do you want to add another car?! ";
cin>>ans;
cout<<endl;
n++;
}while((n<30)&&(strcmp(ans,"yes")==0)||(strcmp(ans,"Yes")==0));
for(int out=1;out<n;out++)
{//those loops are for sorting cars by thier prices ..
for(int in=out;((in>0)&&(P[in]>P[in-1]));in--)
{
xP=P[in];
P[in]=P[in-1];
P[in-1]=xP;
strcpy(xC,C[in]);
strcpy(C[in],C[in-1]);
strcpy(C[in-1],xC);
}//end inner loop
}//end outer loop
}
else//if the user try to enter more than 30 cars , this massage will appeares
cout<<setw(56)<<" -------------(^_^)-------------\n"
<<setw(57)<<"| Sorry but the company is FULL |\n"
<<setw(57)<<"| Try another service |\n"
<<setw(56)<<" -------------------------------\n";
}//end Insert function
void Display(char C[30][10],long P[30],int &n)
{
if(n>0)
{
cout<<setw(51)<<"You chose (DISPLAY)\n"
<<setw(70)<<"Here is a table that shows all the cars in the company\n"
<<setw(55)<<"arranged by thier prices\n\n"
<<setw(67)<<" _________________________________________________\n"
<<setw(68)<<"| no. | THE CAR | THE PRICE |\n"
<<setw(68)<<"|_____|_____________________|_____________________|\n";
for(int d=0;d<n;d++)
{
if(d<9)
cout<<setw(19)<<"| "<<d+1<<" |"<<setw(13)<<C[d]<<" |"<<setw(13)<<P[d]<<" |\n";
else
cout<<setw(19)<<"| "<<d+1<<" |"<<setw(13)<<C[d]<<" |"<<setw(13)<<P[d]<<" |\n";
}
cout<<setw(67)<<"|_____|_____________________|_____________________|";
}//end if statment
else//this massage will appeares if the company was empty
cout<<setw(61)<<" ----------------(^_^)------------------\n"
<<setw(62)<<"| Sorry there is no cars in the company |\n"
<<setw(62)<<"| try to insert cars first please |\n"
<<setw(61)<<" ---------------------------------------\n";
}//end display function
void SearchC(char C[30][10],int &n)
{
int T1=0;
char Scar[10];
cout<<setw(55)<<"Enter the car's name , please :";
cin>>Scar;
for(int s=0;s<n;s++)
{
if(strcmp(C,Scar)==0)
{T1=1;
break;}
}
if(T1==1)
cout<<endl<<setw(53)<<"The car you've been loking for ("<<C<<") is found\n"
<<setw(50)<<"& it's number is ("<<s+1<<")";
else
cout<<endl<<setw(75)<<"(Sorry the car you've been looking for is not found in the company)\n";
}//end searchC function
void SearchP(long P[30],char C[30][10],int &n)
{
int T2=0;
long Sp;
cout<<setw(52)<<"Enter the price , please : ";
cin>>Sp;
for(int sch=0;sch<n;sch++)
{
if(P[sch]==Sp||P[sch]<Sp)
{T2=1;
break;}
}
if(T2==1)
{
cout<<endl<<setw(67)<<"The cars which have this price or less are :\n";
for(int sh=sch;sh<n;sh++)
cout<<setw(43)<<C[sh]<<endl;
}
else
cout<<setw(65)<<"(Sorry but there are no cars with this price)\n";
}//end searchP function
void Delete(char C[30][10],long P[30],int &n)
{
int T3=0;
char Del[10];
if(n>0)
{
cout<<setw(65)<<"Enter the name of the car you want to delete , please : ";
cin>>Del;
for(int d=0;d<n;d++)
{
if(strcmp(C[d],Del)==0)
{T3=1;
break;}
}
if(T3==1)
{
for(int de=d;de<n-1;de++)
{
strcpy(C[de],C[de+1]);
P[de]=P[de+1];
}
cout<<endl<<setw(49)<<"(The car is deleted)";
n--;
}
else
cout<<endl<<setw(75)<<"(Sorry the car which you want to delete is not found in the company)\n";
}//end if statment
else//this massage will appeares if the company was empty
cout<<setw(60)<<" -----------------(^_^)-----------------\n"
<<setw(61)<<"| Sorry there is no cars in the company |\n"
<<setw(61)<<"| try to insert cars first please |\n"
<<setw(60)<<" ---------------------------------------\n";
}//end Delete function
void Exit(int &choice)
{
cout<<endl
<<setw(63)<<" -------------------(^_^)-------------------\n"
<<setw(64)<<"| Well it's been nice working with you |\n"
<<setw(64)<<"| I hope this program was usefull for you |\n"
<<setw(64)<<"| WISH YOU ALL THE BEST |\n"
<<setw(63)<<" -------------------------------------------\n"<<endl
<<setw(58)<<" _______\n"
<<setw(59)<<" /_______/|\n"
<<setw(65)<<" ____| | ||______\n"
<<setw(66)<<" /_____|___|___|/_____/|\n"
<<setw(66)<<"~~~ BYE BYE ~~~| ___' |' ___ C| |\n"
<<setw(65)<<" |__( @ )__|__( @ )__|/\n"
<<setw(61)<<" '-' '-'\n\n";
choice++;
}//end Exit function
