We are going to write a program of Vehicle Registration System. Follow the instructions / problem set below for assignment;
1 – There are two (2) structures in a program named as Vehicle and Owner.
2 – Variables in Vehicle structure are;
Structure of Vehicle
Attribute Name |
Data Type |
Example |
vehicle-type | char | 2 wheel, 3 Wheel, 4 wheel etc. |
maker | char | Honda,Toyota, Suzuki etc. |
year-of-manufacture | int | 2012 etc |
engine-no | char | BR-29536 etc. |
registration-no | char | LEV-0012 etc. |
vehicle-price | unsigned int | 48000 etc. |
3 – Variables in Owner structure are;
Structure of Owner
Attribute Name |
Data Type |
owner-name | char |
father-name | char |
address | char |
date-of-purchase | int |
month-of-purchase | int |
year-of-purchase | int |
transferred-from | char |
4 – Make enumerator named as vehicle-class which has the value set given below. No vehicle is beyond these values.
- Motor Cycle
- Car
- Van
- Sports Car
- Pickup
- Truck
5 – vehicle-class enumerator should be in structure Vehicle.
6 – Instance / variable / object of Vehicle structure is passed in Owner structure.
7 – Initialize the variables in structures. (You may initialize them in structure / main function).
8 – When your program starts, the following lines are appeared on screen.
9 – There are three functions named as:
- View
- Transfer
- Register
10 – These three functions take a single input parameter that is pointer to structure Owner. Functions have return type as void
11 – Handle the choice entered by user by Switch statement.
- If user enters 1 then function View is triggered.
- For option as 2, Transfer function is triggered.
- Option 3 trigger function Register.
- Any other input cause to terminate program.
12 – If user input is from 1 – 3 then your program, performs the required task shows result and then Clear the screen (clrscr () function is used to clear DOS screen. Function is in ‘conio’ header file) and then screen appears as in point 8, until unless users exit the program.
13 – Some Functions implementation details (functions in point 9)
Function View:
– It displays all information stored in Owner Structure. (Vehicle information is also included in Owner Structure)
– Sample Display Screen is provided below;
unction Transfer:
– Sample Display Screen is provided below;
– You have to swap Owner Name and Transferred from then take input from user for the fields as in figure above.
– After that Clear the Screen and call View function to view all information in the structure as shown in Function View description in addition of displaying Transferred from name at the end.
Function Register:
– You have to take input of all variables in structure except Transferred from. (Registration is used for newly buy vehicle)
– Sample Display Screen is provided below;
/****************** Assignment No. 1 : Solution **********************\
#include <iostream.h>
#include <conio.h>
# include <stdlib.h>
#include <string.h>
bool b = 0;
// ———– VEHICLE STRUCTURE ———– //
struct Vehicle
{
char vehicle_type [100], maker [100], engine_no [100], registration_no [100];
int year_of_manufacture;
unsigned int vehicle_price;
enum vehicle_class {Motor_Cycle, Car, Van, Sports_Car, Pickup, Truck}vc;
};
// ————————————— //
// ———– OWNER STRUCTURE ———– //
struct Owner
{
char owner_name [100], father_name [100], address [100], transferred_from [100];
int date_of_purchase, month_of_purchase, year_of_purchase;
Vehicle v;
} owner1 = {“Ali Hussain”, “Muhammad Hussain”, “XYZ, Lahore”, “N/A”, 12, 12,2012, “4-Wheel”,
“Honda”, “BR-29536”, “LEV-0012”, 2011, 72000, Vehicle::Van};
// ————————————— //
// ———– FUNCTION VIEW ———– //
void View (struct Owner *o2)
{
char * vclass;
{
if (o2->v.vc == 0)
vclass = “Motor Cycle”;
else if (o2->v.vc == 1)
vclass = “Car”;
else if (o2->v.vc == 2)
vclass = “Van”;
else if (o2->v.vc == 3)
vclass = “Sports Car”;
else if (o2->v.vc == 4)
vclass = “Pickup”;
else if (o2->v.vc == 5)
vclass = “Truck”;
else
vclass = “Unknown Vehicle Class”;
}
cout<<“====================”<<endl;
cout<<“VEHICLE INFORMATION:”<<endl;
cout<<“====================”<<endl<<endl;
cout<<“Registration No: “<<o2->v.registration_no<<endl;
cout<<“Vehicle Type: “<<o2->v.vehicle_type<<endl;
cout<<“Vehicle Class: “<<vclass<<endl;
cout<<“Maker: “<<o2->v.maker<<endl;
cout<<“Year of Manufacture: “<<o2->v.year_of_manufacture<<endl;
cout<<“Engine No: “<<o2->v.engine_no<<endl;
cout<<“Vehicle Price: “<<o2->v.vehicle_price<<endl<<endl;
cout<<“==================”<<endl;
cout<<“OWNER INFORMATION:”<<endl;
cout<<“==================”<<endl<<endl;
cout<<“Owner Name: “<<o2->owner_name<<endl;
cout<<“Father’s Name: “<<o2->father_name<<endl;
cout<<“Address: “<<o2->address<<endl;
cout<<“Date of Purchasing: “<<o2->date_of_purchase<<” / “<<o2->month_of_purchase;
cout<<” / “<<o2->year_of_purchase<<endl;
if (b == 1)
cout<<“Transferred From: “<<o2->transferred_from<<endl;
}
// ———————————— //
// ———– FUNCTION TRANSFER ———– //
void Transfer (struct Owner *o2)
{
cout<<“======================”<<endl;
cout<<“VEHICLE TRANSFER FORM:”<<endl;
cout<<“======================”<<endl<<endl;
strcpy (o2->transferred_from, o2->owner_name);
cout<<“Buyer Name: “;
cin.sync();
cin.getline (o2->owner_name, 100);
cout<<“Father’s Name: “;
cin.getline (o2->father_name, 100);
cout<<“Address: “;
cin.getline(o2->address, 100);
cout<<“Date of Purchasing: “;
cin>>o2->date_of_purchase;
cout<<“Month of Purchasing: “;
cin>>o2->month_of_purchase;
cout<<“Year of Purchasing: “;
cin>>o2->year_of_purchase;
b = 1;
}
// —————————————– //
// ———– FUNCTION Register ———– //
void Register (struct Owner *o2)
{
int enum_choice;
cout<<“=================================”<<endl;
cout<<“VEHICLE REGISTRATION INFORMATION:”<<endl;
cout<<“====================”<<endl;
cout<<“VEHICLE INFORMATION:”<<endl;
cout<<“====================”<<endl<<endl;
cin.sync();
cout<<“Registration No: “;
cin.getline (o2->v.registration_no, 100);
cout<<“Vehicle Type: “;
cin.getline (o2->v.vehicle_type, 100);
cout<<“Vehicle Class (0 – 5): “;
cin>>enum_choice;
o2->v.vc = (Vehicle::vehicle_class)enum_choice;
cin.sync();
cout<<“Maker: “;
cin.getline (o2->v.maker, 100);
cout<<“Year of Manufacture: “;
cin>>o2->v.year_of_manufacture;
cin.sync();
cout<<“Engine No: “;
cin.getline (o2->v.engine_no, 100);
cout<<“Vehicle Price: “;
cin>>o2->v.vehicle_price;
cout<<“==================”<<endl;
cout<<“OWNER INFORMATION:”<<endl;
cout<<“==================”<<endl<<endl;
cin.sync();
cout<<“Owner Name: “;
cin.getline (o2->owner_name, 100);
cout<<“Father’s Name: “;
cin.getline (o2->father_name, 100);
cout<<“Address: “;
cin.getline(o2->address, 100);
cout<<“Date of Purchasing: “;
cin>>o2->date_of_purchase;
cout<<“Month of Purchasing: “;
cin>>o2->month_of_purchase;
cout<<“Year of Purchasing: “;
cin>>o2->year_of_purchase;
}
// —————————————– //
int main ()
{
int choice;
Owner *owner2 = &owner1;
cout<<“===========================”<<endl;
cout<<“VEHICLE REGISTRATION SYSTEM”<<endl;
cout<<“===========================”<<endl<<endl;
cout<<“1 – View Vehicle Information”<<endl;
cout<<“2 – Transfer Vehicle”<<endl;
cout<<“3 – Register Vehicle”<<endl;
cout<<“0 – Exit from Program”<<endl<<endl;
cout<<“Enter your Choice: “;
cin>>choice;
switch (choice)
{
case 1:
{
system (“cls”);
View (owner2);
break;
}
case 2:
{
system (“cls”);
Transfer (owner2);
system (“cls”);
View (owner2);
break;
}
case 3:
{
system (“cls”);
Register (owner2);
system (“cls”);
View (owner2);
break;
}
default:
exit (0);
}
getch();
return 0;
}
/****************** Download Solution From Here **********************\
CS410_Assignments_Solution_1_Spring_2012