Take your Car and List class from Week 8.
Add functions to the List class that asks the user for a make and then deletes the first match in the list (or just assume all makes are unique in the list).
HINT: Add a deleteCar function to get the make and then call a deleteFromList with the cstring to actually delete the car object from the list.
Car class:
#ifndef CAR_H
#define CAR_H
#define MAX_STR 10
//Car class
class Car
{
private:
char make[MAX_STR];
char model[MAX_STR];
int year;
public:
Car();
~Car(){}
Car(char mk[], char md[], int yr);
char* getMake();
char* getModel();
int getYear();
void setMake(char*);
void setModel(char*);
void setYear(int);
};
List Class:
#ifndef LIST_H
#define LIST_H
#include"car.h"
//Node structure
struct Node
{
Car car;
struct Node *next;
};
//List class
class List
{
private:
Node *head;
public:
List();
~List();
void addCar();
void addToList(Car c);
void printList();
};
#endif // LIST_H
I hope these classes are correct, but if they aren't please let me know!
//Car.h
#define CAR_H
#define MAX_STR 10
//Car class
#include<iostream>
#include<string.h>
using namespace std;
class Car
{
private:
char make[MAX_STR];
char model[MAX_STR];
int year;
public:
Car(){}
~Car(){
}
Car(char mk[], char md[], int yr){
strcpy(make , mk);
strcpy(model , md);
year = yr;
}
char* getMake(){
return make;
}
char* getModel(){
return model;
}
int getYear(){
return year;
}
void setMake(char* mk){
strcpy(make,mk);
}
void setModel(char* md){
strcpy(model , md);
}
void setYear(int yr){
year = yr;
}
};
#endif
//List.h
#include"Car.h"
//Node structure
struct Node
{
Car car;
struct Node *next;
};
//List class
class List
{
private:
Node *head;
public:
List(){
head = NULL;
}
~List(){
struct Node* current = head, * next;
while (current != NULL)
{
next = current->next;
delete(current);
current = next;
}
head = NULL;
}
void addCar(){
char make[MAX_STR],model[MAX_STR];
int year;
cout<<"Enter make: ";
gets(make);
cout<<"Enter model: ";
gets(model);
cout<<"Enter year: ";
cin>>year;
Car c(make,model,year);
addToList(c);
}
void addToList(Car c){
struct Node* newNode = new Node;
newNode->car = c;
newNode->next = NULL;
if(head == NULL){
head = newNode;
return;
}
struct Node* current = head;
while(current->next != NULL)current =
current->next;
current->next = newNode;
}
void printList(){
struct Node* current = head;
while(current !=NULL){
cout<<"Make :
"<<current->car.getMake()<<endl;
cout<<"Model :
"<<current->car.getModel()<<endl;
cout<<"Year :
"<<current->car.getYear()<<endl;
current = current->next;
cout<<endl;
}
}
void deleteFromList(char make[]){
struct Node* current = head , *prev = NULL;
if(head==NULL)return;
if(strcmp(current->car.getMake() , make)==0){
head = current->next;
delete current;
return;
}
while(current !=NULL &&
strcmp(current->car.getMake() , make)!=0){
prev = current;
current = current->next;
}
if(current==NULL)return;
prev->next = current->next;
delete current;
}
};
//main.cpp
#include "List.h"
void deleteCar(List &list){
char make[MAX_STR];
cout<<"\n\nEnter make to delete: ";
gets(make);
list.deleteFromList(make);
}
int main(){
List list;
Car c[3];
char make[MAX_STR],model[MAX_STR];
int year;
for(int i=0;i<3;i++){
cout<<"Enter make: ";
gets(make);
cout<<"Enter model: ";
gets(model);
cout<<"Enter year: ";
cin>>year;
c[i].setMake(make);
c[i].setModel(model);
c[i].setYear(year);
list.addToList(c[i]);
cin.get();
}
list.printList();
deleteCar(list);
list.printList();
return 0;
}
Take your Car and List class from Week 8. Add functions to the List class that...
Codes: (car.h ; car.cpp ; carDemo.cpp) /* ----------------------- Car ----------------------- - make: string - year : int ----------------------- + Car() + setMake(m: string) : void + getMake() : string + setYear(y: int) : void + getYear() : int ---------------------- */ #ifndef CAR_H #define CAR_H #include <iostream> using namespace std; class Car { private: string make; int year; public: Car(); Car(string); Car(int); Car(string, int); void setMake (string); string getMake() {return make;} void setYear (int); int getYear() {return year;} }; #endif #include...
public class Car { /* four private instance variables*/ private String make; private String model; private int mileage ; private int year; // /* four argument constructor for the instance variables.*/ public Car(String make) { super(); } public Car(String make, String model, int year, int mileage) { super(); this.make = make; this.model...
Below are the Car class and Dealership class that I
created In the previous lab
import java.util.ArrayList;
class Car
{
private String make;
private String model;
private int year;
private double transmission;
private int seats;
private int maxSpeed;
private int wheels;
private String type;
public Car()
{
}
public Car(String make, String model, int year, double transmission, int seats, int maxSpeed, int wheels, String type) {
this.make = make;
this.model = model;
this.year = year;
this.transmission = transmission;
this.seats =...
Show the compilation of Programming Challenge below in separate header and implementation files and show a UML diagram of this class. #include “Car.h” Int main() { Car car(2015, “Volkswagon”); Cout<<”Car’s Make: “ << car.getMake() <<endl; Cout<< “Car’s Year:” << car.getYear() <<endl; Cout<< “Car’s Speed : “ <<car.getSpeed()<<endl; Cout<< endl; For(int I =0; I < 5; i++) { Car.acceleration(); Cout<< “Speed after accelerate: “ << car.getSpeed() << endl; } For(int I = 0; i < 5; i++) { Car.brake(); Cout <<...
Please answer in C++. Derive a class called Stack from the linked list described in Assignment 2 (list of Dates). This means the Stack class will inherit all the properties (data and functions) of the linked list. But, since a stack only allows pushing and popping at the front of the list only, you will need to prevent the operations at the back. To do this, derive the Stack class in such a way that the base class (LinkedList) functions...
Please answer in C++ Derive a class called Queue from the linked list described in Assignment 2 (list of Dates). This means the Queue class will inherit all the properties (data and functions) of the linked list. But, since a queue allows pushing only at the back and popping at the front of the list, you will need to prevent the addition in the front and removal at the back. To do this, you must derive the Queue class in...
Language = C++ How to complete this code? C++ Objects, Structs and Linked Lists. Program Design: You will create a class and then use the provided test program to make sure it works. This means that your class and methods must match the names used in the test program. Also, you need to break your class implementation into multiple files. You should have a car.h that defines the car class, a list.h, and a list.cpp. The link is a struct...
Please put the following pseudocode into C++. Below the pseudocode is a header file as well as a cpp file that needs to be included. // Start // Declarations // Automobile myAuto // string vin // string make // string model // string color // output "Please enter the Vehicle Identification Number: " // input vin // output "Please enter the Make: " // input make // output "Please enter the Mode: " // input model // output "Please enter...
Can someone help me with my Java code error! Domain package challenge5race; import java.util.Random; public class Car { private int year; private String model; private String make; int speed; public Car(int year, String model, String make, int speed) { this.year = year; this.model = model; this.make = make; this.speed = speed; } public Car() { } public int getYear() { return year; } public void setYear(int year) { this.year = year; } public String getModel() { return model; }...
IntList Recursion Assignment Specifications: You will add some additional recursive functions to your IntList class as well as make sure the Big 3 are defined. IntNode class I am providing the IntNode class you are required to use. Place this class definition within the IntList.h file exactly as is. Make sure you place it above the definition of your IntList class. Notice that you will not code an implementation file for the IntNode class. The IntNode constructor has been defined...