help needed again

This is a discussion on help needed again within the C++ Programming forums, part of the General Programming Boards category; hi i need an alogorithm for this program not too long just breif here is the program:- Code: //RENT A ...

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

    help needed again

    hi i need an alogorithm for this program not too long just breif

    here is the program:-

    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
    Registered User
    Join Date
    Jan 2009
    Posts
    6
    i m fairly new to programming.
    this is a program i lifted from a cluster of many.i need an algorithm to understand some parts of it.

    your help in this matter is appreciated sincerely.

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    The algorithm for understanding some parts of it is called "tracing". Sit down with a blank piece of paper and the program. Write all the variable names across the top. Go through the program, line by line, "executing" each command as though you were the computer. (You'll have to switch to "user" when the program asks for input, but that shouldn't be that bad.)

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,455
    Just use a debugger instead, to step through.
    Visual Studio provides an excellent one.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    The advantage of doing it by hand is that you cannot cheat - you can only progress if you actually understand what any given line does.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,455
    But on the other hand - it's usually too much to write down and tedious, plus it can be difficult to find out what it does, which is easier with a debugger.
    Why play with pen and paper when we have proper tools today? That is why I'm pro-debugger and anti-paper.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,453
    Quote Originally Posted by Elysia
    But on the other hand - it's usually too much to write down and tedious, plus it can be difficult to find out what it does, which is easier with a debugger.
    In practice, yes.

    Quote Originally Posted by Elysia
    Why play with pen and paper when we have proper tools today?
    Because Vikramnb may be restricted to pen and paper during an exam, and learning to analyse a program even without the aid of a debugger allows one to appreciate the power of a debugger.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,455
    Quote Originally Posted by laserlight View Post
    Because Vikramnb may be restricted to pen and paper during an exam, and learning to analyse a program even without the aid of a debugger allows one to appreciate the power of a debugger.
    *shrug*
    I feel that silly, seeing how much computers have evolved today.
    Why oh why are we still taking notes on papers or writing tests on papers (aside from the cost of computers, of course)?

    Well, whatever. It's up to the OP anyway.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. free needed or not?
    By quantt in forum Linux Programming
    Replies: 3
    Last Post: 06-25-2009, 09:32 AM
  2. C Programmers needed for Direct Hire positions
    By canefan in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 09-24-2008, 11:55 AM
  3. lock needed in this scenario?
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 05-25-2008, 07:22 AM
  4. C++ help needed
    By Enkindu in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 08-31-2004, 11:24 PM
  5. semi-colon - where is it needed
    By kes103 in forum C++ Programming
    Replies: 8
    Last Post: 09-12-2003, 05:24 PM

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