- 5th May 2022
- 06:03 am
This program is used to manage the detail of the vehicle, you can add, remove and update the data of the vehicle.
create a class name Automobile with the following attributes{
private string make
private string model
private string color
private int year
private int mileage
End
}
create a base class name Dealership with Automobile as parent class{
define construcor of this class
defin function add(){
Read Make, Model, Color, Year, Milage of the vehice and store it into the class variable
open file 'Data.txt' in append mode
concatenate Make, Model, Color, Year, Milage into one string with ';' b/w them and store it in l
write l in file
close the file
print data added
End
}
define function remove(){
Read model from user whose data you want to remove
initialize found=0
open 'Data.txt' in read mode
open 'temp.txt' in write mode
read all the data of file Data.txt in l
iterate in l with the help of i:
replace "\n" to "" in string i and store it in j
split string j with semicolon and store it in line
if(line[1]==model):
set found=1
print data removed
else:
write i in file temp.txt
close temp.txt file
close data.txt file
remove data.txt file from the computer
rename temp.txt to Data.txt
check if found is equal to 0
print no data found
End
}
define function update(){
Read model from user whose data you want to update
Read from user what he want to update and store it in choice
initialize found=0
open 'Data.txt' in read mode
open 'temp.txt' in write mode
read all the data of file Data.txt in l
iterate in l with the help of i:
replace "\n" to "" in string i and store it in i
split string i with semicolon and store it in line
if(line[1]==model):
if choice==1:
Read New Make
assign New Make to line[0]
elif choice==2:
Read New Model
assign New Model to line[1]
elif choice==3:
Read New Color
assign New Color to line[2]
elif choice==4:
Read New Year
assign New Year to line[3]
elif choice==5:
Read New Milage
assign New Milage to line[4]
else:
print Wrong choice
set found=1
print Data Updated"
set i=""
for j in line:
i=i+j+";"
remove the last element of i
write i in file temp.txt
write "\n" in file temp.txt
close temp.txt file
close data.txt file
remove data.txt file from the computer
rename temp.txt to Data.txt
check if found is equal to 0
print no data found
End
}
End
}
create object of Dealership class
print menu to user aand ask him what he want to do
if he choose to add a vehicle
call add function using object
if he choose to remove a vehicle
call remove function using object
if he choose to update a vehicle
call update function using object
if he chosses other than this print wrong choice