Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that allows the member to search for cars for sale based on the

ID: 3740895 • Letter: W

Question

Write a program that allows the member to search for cars for sale based on the car_no. The program allows the member to enter the car_no . If no cars are matched by the given car_no, then the program displays a proper message indicating that no cars are found. Otherwise, the program lists all cars matching that car_no. Each car entry in the list displayed consists of an integer starting at 1, the name of the seller and price of the car. For example, if 4 cars match the given car_no, the program adds the integer as such: 1 Seller: John Wright, Price: $2,000.00, etc.... After the cars are listed, the program asks the member to make a selection based on the integer value. Once the member makes the selection, the entry is added to the shopping cart.

Explanation / Answer

#include<iostream>

#include<string>

using namespace std;

class car{

public:

int car_no;

string sellername;

float price;

string model;

car()

{

cout<<" Enter the car number:";

cin>>car_no;

cout<<" Enter the Sellername:";

cin>>sellername;

cout<<" Enter the price of car:$";

cin>>price;

cout<<" Enter the model of car:";

cin>>model;

}

car(int n)

{

}

};

class sale_car{

int n,numcarts;

car *p;

int *carts;

public:

sale_car()

{

int i;

numcarts=0;

cout<<"Enter the number of cars: ";

cin>>n;

p=new car[n];

carts=new int[n];

}

void addtocart(int c)

{

if(numcarts<n)

carts[numcarts++]=c;

}

void showcarts()

{

int i;

cout<<" Cart Status is : ";

for(i=0;i<numcarts;i++)

cout<<" "<<i+1<<" Seller:"<<p[carts[i]].sellername<<" Price:$ "<<p[carts[i]].price;

}

void sell(int number)

{

int i,k=0,s[n];

for(i=0;i<n;i++)

if(number==p[i].car_no)

{

s[k++]=i;

cout<<" "<<k<<" Seller:"<<p[i].sellername<<" Price:$"<<p[i].price;

}

if(k!=0)

{

cout<<" Enetr your choice:";

cin>>k;

addtocart(s[k-1]);

}

else

cout<<" No cars Available:";

}

};

int main()

{

int number;

sale_car sc;

cout<<"Enter the car number to buy:";

cin>>number;

sc.sell(number);

sc.showcarts();

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote