Urgent Help Needed In Writing Algorithm!!

This is a discussion on Urgent Help Needed In Writing Algorithm!! within the C++ Programming forums, part of the General Programming Boards category; Urgent help needed in writing algortithm for this program!! thankyou Code: //RENT A CAR PROJECT #include<iostream.h> #include<fstream.h> #include<stdio.h> #include<conio.h> #include<string.h> ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    6

    Urgent Help Needed In Writing Algorithm!!

    Urgent help needed in writing algortithm for this program!!

    thankyou

    Code:
    //RENT A CAR PROJECT
    #include<iostream.h>
    #include<fstream.h>
    #include<stdio.h>
    #include<conio.h>
    #include<string.h>
    #include<dos.h>
    #include<stdlib.h>
    #include<limits.h>
    #include<iomanip.h>
    class Car
    {
    	private:
    		unsigned long s_no;
    		char strName[25];
    		int nDays;
    		char strType;
    		char strCompany[10] ;
    		int nAge;
    		char strDesig[10],strPIan;
    		int nCost; 
    		int ndln;
    		int nPhone;
    		char strWeekEnd;
    		char strSex;
    		int nBox;
    		int nPlan;
    
    	public:
    		unsigned long_get( );
    		void GetDetails( );
    		void Individual( );
    		void Status( );
    		void Company( ); 
    		void AddDetails( );
    		void ShowDetails( );
    		void ShowObject( );
    		void DeleteObject( );
    		void Modify( );
    	//	void Reports( );
    		void Search( );
    };
    Car cars;
    
    void Car::GetDetails( )
    {
    	char choice;
    	char use;
    
    
    		cout<<"Select Car Type\n";
    		cout<<"Economy .... .A\n";
    		cout<<"Luxury ......... B\n";
    		cout<<"4 x 4 .......... .C\n";
    		cout<<"Exit ............ ";
    		cin>>choice;
    
    		if((choice=='A')||(choice=='B')||(choice=='C'))
    		{
    			cout<<"please enter \n P for personal use or \n";
    			cout<<"C for company use";
    			cin>>use;
    			if(use=='P')
    				Individual();
    			else if (use=='C')
    			 Company();
    
    		}
    		else
    			cout<<"wrong option "; 
    }
    
    void Car::Individual()
    {
     
    	system ("CLS");
    	cout<<"enter the customer name\n";
    	cin>>strName;
    	cout<<"enter the age\n";
    	cin>>nAge;
    	cout<<"enter• the gender";
    	cin>>strSex;
    	cout<<"enter the driving license no\n";
    	cin>>ndln;
    	cout<<"enter the PO box\n";
    	cin>>nBox;
    	cout<<"enter the company\n";
    	cin>>strCompany;
    	cout<<"enter the destination\n";
    	cin>>strDesig;
    	cout<<"enter the phone no\n";
    	cin>>nPhone;
    	cout<<"you may proceed\n";
    	cout<<"1 ..... day plan\n";
    	 cout<<"2 ..... weekly plan\n";
    	 cout<<"3. .... monthly plan\n";
    	 cout<<"4 ..... yearly plan\n";
    
    cin>>nPlan;
    	switch(nPlan)
    	{
    		case 1:
    			 cout<<"is it a weekend(Y or N)\n";
    			 cin>>strWeekEnd;
    			  if(strWeekEnd='y')
    			  {
    				  int temp=50;
    				  cout<<"enter the no of days";
    				  cin>>nDays;
    				  nCost=(cars.nDays* 100)+temp;
    				cout<<nCost;
    			  }
    			 else
    			 { 
    				cout<<"enter the number of days";
    				cin>>nDays ; 
    				nCost=cars.nDays*100;
    				cout<<nCost;
    			 }
    			break;
    		  case 2:
    			  cout<<"enter the number of weeks";
    			  cin>>nDays;
    			  nCost=cars.nDays*90*7;
    			  cout<<nCost;
    			  break;
    		  case 3:
    			cout<<"enter the number of months";
    			cin>>nDays;
    			nCost=cars.nDays*65*30;
    			cout<<nCost;
    			break;
    
    		 case 4:
    			cout<<"enter the number of years";
    			cin>>nDays;
    			nCost=cars.nDays*35*365;
    			cout<<nCost;
    			break;
    
    		default:
    			cout<<"please check your option";
    	}
    }
    
    void Car::Company()
    {
    	int nRate=0;
    	char strdriver;
    	char company[10];
    		cout<<"company name";
    		cin>>company;
    		cout<<"do you need a driver";
    		cin>>strdriver;
    	if(strdriver=='y')
    	{
    		nRate=2000;
    	}
    	else
    	{
    		nRate=0;
    	}
    		char name[10];
    		int dln;
    		int box;
    		int plan;
    		int month,cost,year;
    		cout<<"enter the driver's name";
    		cin>>name;
    		cout<<"enter the driving license number";
    		cin>>dln;
    		cout<<"enter the PO box";
    		cin>>box;
    		cout<<"please enter the plan";
    		cout<<"l ..... monthly plan";
    		cout<<"2 ...., yearly plan";
    		cin>>plan;
    	switch(plan)
    	{
    		case 1:
    			cout<<"please enter the number of months";
    			cin>>month;
    			cost=(1200*month)+(nRate*month);
    			cout<<cost;
    		break;
    		case 2:
    			cout<<"please enter the number of years" ;
    			cin>>year;
    			cost=(9125*year)+(year*nRate*12);
    			cout<<cost;
    		break;
    
    	}
    	
    }
    
    void Car::Status()
    {
    	char choice=0;
    	int counter=0;
    
    	fstream infile;
    	infile.open("car",ios::in);
    	infile.seekg(0,ios::beg);
    	infile.read((char*)&cars,sizeof(cars));
    
    	while(!infile.eof( ))
    	{
    	if(cars.strType==choice)
    	counter=counter+1 ;
    	}
    	if (counter<5)
    	{
    		cout<<"cars are available";
    		cout<<"pIease continue";
    	}
    	else  
    	{
    		cout<<"no cars are available";
    		cout<<"enter another type of car";
    		Status ();
    	}
    }
    
    void Car::ShowDetails()
    {
    system ("CLS");
    	cout<<"customer name"<<strName;
    	cout<<"age"<<nAge;
    	cout<<"type"<<strType;;
    	cout<<"gender"<<strSex;;
    	cout<<"driving license number"<<ndln;;
    	cout<<"mobi1e"<<nPhone;
    	cout<<"p.o.box"<<nBox;;
    	cout<<"plan"<<strPIan;
    	cout<<"cost"<<nCost; 
    	cout<<"press any key to continue";
    	getch();
    }
    
    void Car::AddDetails()
    {
    fstream outfile;
    char choice='y';
    	while(choice=='y')
    	{
    	system ("CLS");
    		//char ch;
    		outfile.open("car",ios::app);
    		cars.GetDetails();
    		outfile.write((char*)&cars,sizeof(cars));
    		outfile.flush();
    		outfile.close();
    		cout<<"any more customers";
    		cin>>choice;
    	}
    }
    void Car::ShowObject()
    {  
    	fstream infile; 
    	infile.open("car",ios::in);
    	infile.seekg(0,ios::beg);
    	infile.read((char*)&cars,sizeof(cars));
    	while(!infile.eof())
    	{
    	cars.ShowDetails();
    	infile.read((char*)&cars,sizeof(cars));
    	}
    }
    
    void Car::DeleteObject()
    {
    	int code;
    	fstream infile,outfile;
    	cout<<"enter the dln to be deleted";
    	cin>>code;
    	outfile.open("tempfile",ios::app);
    	infile.open("car",ios::in);
    	infile.seekg(0,ios::beg);
    	infile.read((char*)&cars,sizeof(cars));
    	while(infile.eof())
    	{
    		if(cars.ndln!=code)
    		outfile.write((char*)&cars,sizeof(cars));
    		infile.read((char*)&cars,sizeof(cars));
    	}
    	infile.close();
    	outfile.close();
    	remove("car");
    	rename("temp","car");
    }
    /*void Car::Modify()
    {
    	fstream file;
    	int code;
    	int mod_choice,month;
      do 
    	{ 
    	//	clrscr();
    		cout<<"modify menu"<<'\n';
    		cout<<"change number of days\t1 "<<'\n';
    		cout<<"change contact person\t2"<<'\n';
    		cout<<"mobile number\t3"<<'\n';
    		cout<<"exit modify menu\t4"<<'\n';
    		 cout<<"PLEASE ENTER YOUR CHOICE\t\n";
    		cin>>mod_choice;
    if(mod_choice<4)
    {
    	cout<<"driving license number";
    	cin>>code;
    	file.open("car",ios::app);
    	file.seekg(0,ios::beg);
    	file.read((char*)&cars,sizeof(cars));
    	int n=file.tellg();
    	while(!file.eof());
    	{
    		if (code==cars.ndln)
    		{
    			switch(mod_choice)
    			{
    				case 1:
    				system ("CLS");
    					cout<<"enter the number of days";
    					cin>>month;
    					file.seekg(n-sizeof(cars));
    					file.write((char*)&cars,sizeof(cars));
    					file.flush();
    				break;
    				case 2:
    					system ("CLS"); 
    					cout<<"enter the contact person";
    					  gets(cars.strName);
    					  file.seekg(n-sizeof(cars));
    					//file.flush((char*)&cars,sizeof(cars));
    					file.flush();
    				break;
    				 case 3:
    					system ("CLS");
    					cout<<"enter the new phone number";
    					cin>>cars.nPhone;;
    					file.seekg(n-sizeof(cars));
    					file.write((char*)&cars,sizeof(cars));
    					file.flush();
    				break;
    				 default:
    				file.read((char*)&cars,sizeof(cars));
    				n=file.tellg();
    			}
    
    		file.close();
    		
    	}
     }while(mod_choice !=4);
    system ("CLS");
    	cout<<"you ended your modifying session";
    	cout<<"thank you";
    }*/
    void Car::Modify()
    {
    	fstream file;
    	int code;
    	int mod_choice,month;
        do 
    	{ 
    
    			//	clrscr();
    		cout<<"modify menu"<<'\n';
    		cout<<"change number of days\t1 "<<'\n';
    		cout<<"change contact person\t2"<<'\n';
    		cout<<"mobile number\t3"<<'\n';
    		cout<<"exit modify menu\t4"<<'\n';
    		 cout<<"PLEASE ENTER YOUR CHOICE\t\n";
    		cin>>mod_choice;
    		if(mod_choice<4)
    		{
    
    			cout<<"driving license number";
    			cin>>code;
    			file.open("car",ios::app);
    			file.seekg(0,ios::beg);
    			file.read((char*)&cars,sizeof(cars));
    			int n=file.tellg();
    			while(!file.eof());
    			{
    				if (code==cars.ndln)
    				{
    						switch(mod_choice)
    					{
    						case 1:
    						system ("CLS");
    							cout<<"enter the number of days";
    							cin>>month;
    							file.seekg(n-sizeof(cars));
    							file.write((char*)&cars,sizeof(cars));
    							file.flush();
    						break;
    						case 2:
    							system ("CLS"); 
    							cout<<"enter the contact person";
    							  gets(cars.strName);
    							  file.seekg(n-sizeof(cars));
    							//file.flush((char*)&cars,sizeof(cars));
    							file.flush();
    						break;
    						 case 3:
    							system ("CLS");
    							cout<<"enter the new phone number";
    							cin>>cars.nPhone;;
    							file.seekg(n-sizeof(cars));
    							file.write((char*)&cars,sizeof(cars));
    							file.flush();
    						break;
    						 default:
    						file.read((char*)&cars,sizeof(cars));
    						n=file.tellg();
    					}
    				}
    				
    			}
    				file.close();
    		} // end if
    	}while(mod_choice !=4); // end do
    	system ("CLS");
    	cout<<"you ended your modifying session";
    	cout<<"thank you";
    }
    
    
    
    
    int main()
    { 
    
    	int main_choice;
    	do
    	{
    		system ("CLS");
    		cout<<"main menu\n";
    		cout<<"new hire 1\n";
    		cout<<"modify  2\n";
    		cout<<"reports 3\n";
    		cout<<"delete 4 \n";
    		cout<<"show data 5\n";
    		cout<<"exit 6\n";
    		cout<<"enter your choice\n";
    		cin>>main_choice;
    			switch (main_choice)
    			{
    				case 1:
    				cars.AddDetails();
    				break;
    				case 2:
    					cars.Modify();
    				break;
    				case 3:
    					//	cars.reports();
    				break;
    				case 4:
    					cars.DeleteObject( );
    				break;
    				case 5:
    					cars.ShowObject();
    				break;
    				case 6:
    				 system ("CLS");
    					cout<<"you have ended this session\n";
    					cout<<"thank you\n";
    				break;
    			
    			}
    	}while(main_choice!= 5);
    cin.get();
    }

  2. #2
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    Posting the same question multiple times will not get you help any faster, and in fact may discourage people from helping you.

    Also, please read the Homework policy.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help Needed: Borland C++ 5.5 Installation - URGENT!
    By Linette in forum C++ Programming
    Replies: 12
    Last Post: 03-09-2002, 06:44 PM
  2. string searching algorithm......help
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 12-07-2001, 09:59 AM
  3. urgent help needed
    By david in forum C Programming
    Replies: 0
    Last Post: 11-27-2001, 08:27 AM
  4. Urgent Help Needed
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 11-25-2001, 07:48 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21