الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

برنامج ماضبط معي

مغلق
بدأه مبرمجة ++C في 21 فبراير 2005 · 2 رد · 310 مشاهدة · في ارشيف قسم C/C++
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع
#include<iostream.h>
#include<fstream.h>
#include "vehicle.h"
#include "vehicles.h"

int main()
{

	char ch;
	VehicleList vehicle;
	Vehicle v;
	Name = new char[150];
	int NumOfSeat;
	int EngSize;
	int NumOfWh;

	int i;

	do{
  cout << "\n\n";

  cout << "\t1.Add vehicle.\n";
  cout << "\t2.delete vehicle.\n";
  cout << "\t3.find vehicle.\n";
  cout << "\t4.print vehicle.\n";
        cout << "\t5.printReverse vehicle.\n";
  cout << "\t6.Exit.\n";
  cout << "\t?";
  
  cin >> ch;

  switch (ch)
  {
 	 case '1':
    cout << "\nENTER THE VEHICLE NAME: ";
    cin >>  v.Name;
    cout <<"\t THE NUMOFSEAT IS: ";
    cin >> v.NumOfSeat;
    cout << "\t THE ENGSIZE IS: ";
    cin >> v.EngSize;
    cout << endl << "\t THE NUMOFWH IS: ";
     	 cin >> v.NumOfWh;

    vehicle.addVehicle( v );
    break;

 	 case '2':
    cout << "\nENTER THE VEHICLE NAME: ";
    cin >> Name;
    if(!vehicle.deleteVehicle( Name ))
   	 cout<<"THERE IS NO VEHICLE";
    else
   	 cout<<"THE VEHICLE WILL BE DELETED:\n";

    break;

 	 case '3':
    cout << "\nENTER THE VEHICLE NAME: ";
    cin >> Name;
    v = vehicle.findVehicle( Name );
    cout << endl <<"\t THE VEHICLE NAME IS: "<< v.Name;
    cout << endl <<"\t THE NUMOFSEAT IS: "<< v.NumOfSeat;
    cout << endl << "\t THE ENGSIZE IS: " << v.EngSize;
    cout << endl << "\t THE NUMOFWH IS: " << v.NumOfWh;
    break;

 	 case '4':
    vehicle.print();
    break;

 	 case '5':
    vehicle.printReverse();
    break;
 	 }
  
  
  } while( ch!='6' );

	return 0;
}
//end main

-------------------------------------------------------------------
#include<iostream.h>
#include<cstring>
#include"vehicle.h"

//constructor
Vehicle::Vehicle()
{  
	Name = new char[150];
	for ( int i = 0;i < 150;i++ )
  Name = NULL;

	NumOfSeat = 0;
	EngSize = 0;	
	NumOfWh = 0;            // initialize variables
}
// copy constructor
Vehicle::Vehicle( const Vehicle&v )    
{
	for ( int i = 0;i < 150;i++ )
  Name = v.Name;
  NumOfSeat = v.NumOfSeat;
  EngSize = v.EngSize;	
  NumOfWh = v.NumOfWh;
}

void Vehicle::setVehicle( char* name, int seats, int engsize, int wheels)
{
    int j;
	if ( ( ( int )strlen( name ) > 150 ) )
  j = 150;
	else
  j = ( int )strlen( name );

	for ( int i= 0;i < j;i++ )
  Name = name;
  
	if(seats > 0 && seats < 100)
  NumOfSeat = seats;

	if( engsize > 0 && engsize < 10000)
  EngSize = engsize;

	if( wheels > 0 && wheels < 20 )
  NumOfWh = wheels;
}
char *getName()
{
  return Name;
}
int getNumOfVh()
{
	return EngSize;
	return NumOfSeat;
	return NumOfWh;
}

------------------------------------------------------	

#include<iostream.h>
#include<fstream.h>
#include
#include "vehicle.h"
#include "vehicles.h"

// constructor
VehicleList::VehicleList()
{
	count = 0;
	int swap;
	Vehicle v;
	ifstream file;
	file.open( "vehicle.txt" );
	while ( ! file.eof() )
	{
  file.getline( Vecarray[count].Name,150,'\n' );
  file >> Vecarray[count].NumOfSeat;
        file.seekg( 4,ios::cur );
  count++;
	}
	for(int i = 0;i< count-1;i++)
 	 for(int j = i+1;j < count;j++)
 	 {
   	 v = strcmp( Vecarray.Name,Vecarray[j].Name);
   	 if ( v == 1 )
   	 {
      swap = Vecarray;
      Vecarray = Vecarray[j];
      Vecarray[j] = swap;
   	 }
 	 }
  count++;
  
	}
	file.close();


}// end constructor
VehicleList::VehicleList( const Vehicle& v )
{
    for( int i = 0;i < v.count;i++ )
  Vecarray=v.Vecarray;
	count = v.count;
}
// destructor
VehicleList::~VehicleList()
{
	delete [] Vecarray;
}// end destructor

// to get first element from list
Vehicle *getFirst() const
{
	return &Vecarray[ 0 ];
}// end function getFirst

// to get last element from list
Vehicle *getLast() const
{
	return &Vecarray[ count ];
}// end function getLast

// to set first elemnet from the list
bool setFirst( Vehicle *input_first )
{
	Vecarray[0] = *input_first;
	return true;
}// end function setFirst

// to set last elemnet from the list
bool setLast (Vehilce *input_last )
{
	Vecarray[count] = *input_last;
	return true;

}// end function setLast

bool addVehicle ( Vehicle* n)
{
	Vehicle v;
	int swap;
   	 Vecarray[count-1] = n;


  for( int i = 0;i < count;i++)
 	 for( int j = i+1;j< count;j++)
 	 {
    
   	 v = strcmp(v.Name,Vecarray[j].Name);
   	 if ( v == 1 )
   	 {
      swap = Vecarray;
      Vecarray = Vecarray[j];
      Vecarray[j] = swap;
   	 }
 	 }
	count++;
	return true;
}


}// end function addVehicle

// search to any vehicle
Vehicle *findVehicle( char* input_name )
{
	bool found = false;
	int swap;
	for(int i = 0;i < count-1;i++)
	{
   swap = strcmp( Vecarray.Name,Name );

  if ( swap == 0 )
  {
 	 found = true;
 	 return Vecarray;
  }
	}
	if( found == false )
  cout << " THE RECORD NOT FOUND" << endl;
}


}// end function findVehicle

bool deleteVehicle( char* input_name )
{
	bool deleted = false;
	int swap;
	for( int i = 0;i < count;i++)
	{
  swap = strcmp( Vecarray.input_name,input_name );

  if (swap == 0 )
  {
 	 
 	 for(int j = i;j < count;j++)
    Vecarray[j] = Vecarray[j+1];
 	 
 	 count--;
 	 deleted = true;
 	 break;
  }
	}
	if(deleted == false )
  cout<< " THE RECORD NOT FOUND"<<endl;
	return deleted;
}

// print all vehicles
void Vehicle::print() const
{
	for ( int i = 0; i < count-1; i++)
	{
  cout << endl << endl <<"THE PATIENT NUMBER "
    << i << " IS: " << endl;
  cout << endl << "\t THE VEHICLE NAME IS: "<< Vecarray.Name;
  cout << endl << "\t THE NUMOFSEAT IS: "<< Vecarray.NumOfSeat << endl;
  cout << endl << "\t THE ENGSIZE IS: " << Vecarray.EngSize;
  cout << endl << "\t THE NUMOFWH IS: " << Vecarray.NumOfWh;
	}

}// end function print

// to print all information of vehicle's in reverse order
void printReverse() const
{
	for ( int i = 20; i > 0; i-- )
  cout << Vecarray[ i ] << endl;

}// end func

تم تعديل هذه المشاركة بواسطة مبرمجة ++C في 21 فبراير 2005 في 22:49

#2
// header file for vehilce

#ifndef VEHICLE_H
#define VEHICLE_H

class Vehicle {

public:
	Vehicle(); // constructor
	Vehicle( const Vehicle& );
	char* Name;
	int NumOfSeat;
	int EngSize;
	int NumOfWh;
};
#endif
// end header

-------------------------

//header file for vehicleList
#ifndef VEHICLES_H
#define VEHICLES_H

#include "vehicle.h"
 //composition from vehicle header

class VehicleList{

private:
	Vehicle Vecarray[20];
	int count;

public:
    VehicleList();     // constructor

	~VehicleList();    // destructor
    // gets the first element in the list
	Vehicle *getFirst() const;

    // gets the last element in the list
	Vehicle *getLast() const;

	// sets the first element in the list
	bool setFirst( Vehicle *input_first );

	// sets the last element in the list 
	bool setLast (Vehilce *input_last );


	// adds a vehicle in SORTED order (by name)
	bool addVehicle ( Vehicle* ); 

	// finds a vehicle by name
	Vehicle *findVehicle( char* input_name );

	// deletes the first vehicle matching that name
	bool deleteVehicle( char* input_name );

	// prints all vehicle's information in order
	void print() const; 

    // prints all vehicle's information in reverse order
	void printReverse() const; 


};
#endif  //end header

هذي ملفات الهيدر وملف التكست الي نقرى منه مرفق

vehicles.txt

#3
// header file for vehilce

#ifndef VEHICLE_H
#define VEHICLE_H

class Vehicle {

public:
	Vehicle(); // constructor
	Vehicle( const Vehicle& );
	char* Name;
	int NumOfSeat;
	int EngSize;
	int NumOfWh;
};
#endif
// end header

-------------------------

//header file for vehicleList
#ifndef VEHICLES_H
#define VEHICLES_H

#include "vehicle.h"
 //composition from vehicle header

class VehicleList{

private:
	Vehicle Vecarray[20];
	int count;

public:
    VehicleList();     // constructor

	~VehicleList();    // destructor
    // gets the first element in the list
	Vehicle *getFirst() const;

    // gets the last element in the list
	Vehicle *getLast() const;

	// sets the first element in the list
	bool setFirst( Vehicle *input_first );

	// sets the last element in the list 
	bool setLast (Vehilce *input_last );


	// adds a vehicle in SORTED order (by name)
	bool addVehicle ( Vehicle* ); 

	// finds a vehicle by name
	Vehicle *findVehicle( char* input_name );

	// deletes the first vehicle matching that name
	bool deleteVehicle( char* input_name );

	// prints all vehicle's information in order
	void print() const; 

    // prints all vehicle's information in reverse order
	void printReverse() const; 


};
#endif  //end header

هذي ملفات الهيدر وملف التكست الي نقرى منه مرفق

vehicles.zip

هذا الموضوع مغلق.

مواضيع مشابهة