Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE SOLVE USING C++ Problem A: People and vehicles (20 points) For this part you will be keeping information on people and what cars they

PLEASE SOLVE USING C++

Problem A: People and vehicles (20 points) For this part you will be keeping information on people and what cars they are driving. Your program should have the following options: p : create a new person in the database (you may assume this person's name is only one word) c : create a new car in the database (you may assume the car's name will be only one word) f : find and select a person in the database (if there is no such person, show no one) r : register the current person selected to a specified car (if there is no such car, they should be unregistered to any current cars) You may assume there will be no more than 100 cars in the database and no more than 100 people. If you try and find (and select) a person that doesn't exist, show no one for both the person and car. If a person is not registered to a car, show no one for the car. You may assume all people have different names and all cars have different names. However, a car and person might have the same name (see example 2). Each person can only be registered to a single car, but a car can have multiple people registered to it simultaneously (see example 3). Hint 1: use classes (and don't dump everything in a single function) Hint 2: use pointers (really!) or you might regret it when part B comes around

Example 1 (user input underlined): Currently looking at:

Person: No one

In car: No one

Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit

p

What is this person's name?

qinshu

Currently looking at: Person: No one

In car: No one

Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit

c

What is this car's name?

putput

Currently looking at:

Person: No one

In car: No one

Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit

f

Which person do you want to find?

qinshu

Currently looking at:

Person: qinshu

In car: No one

Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit

r

Which car do you wish to register this person to?

putput

Currently looking at:

Person: qinshu

In car: putput

Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit

r

Which car do you wish to register this person to?

mcstinks

Currently looking at:

Person: qinshu

In car: No one

Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit

f

Which person do you want to find?

ahmed

Currently looking at:

Person: No one In car: No one

Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit

p

What is this person's name?

ahmed

Currently looking at:

Person: No one

In car: No one

Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit

f

Which person do you want to find?

ahmed

Currently looking at:

Person: ahmed

In car: No one

Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit

q

--------------------USE THE FOLLOWING CODE FROM PART A TO SOLVE PART B, PART A ALREADY SOLVED------------------------------------------------------------------

#include #include #include using namespace std;

class PersonCar {

string Person[100];

string Car[100];

int RegisterCar[100]; public:

PersonCar();

char Menu();

void CreatePerson();

void CreateCar();

void Register(int);

void CurrentStatus(int);

int Find(); };

void PersonCar::CreatePerson() { string name; int flag = 0;

cout<<" What is this Person's name? "<>name;

for(int x = 0; x < 100; x++) {

if(Person[x] != "") {

if(Person[x] == name) {

flag = 1;

break; } } }

if(flag == 0) {

for(int x = 0; x < 100; x++) {

if(Person[x] == "") {

Person[x] = name; break; } } }

else cout<<" Person name already exist!"; } void PersonCar::CreateCar() { string name; int flag = 0;

cout<<" What is this Cars's name? "<>name;

for(int x = 0; x < 100; x++) {

if(Car[x] != "") {

if(Car[x] == name) {

flag = 1;

break; } } }

if(flag == 0) {

for(int x = 0; x < 100; x++) {

if(Car[x] == "") {

Car[x] = name; break; } } }

else cout<<" Car name already exist!"; }

void PersonCar::Register(int na) { string car; int carInd = -1, x;

cout<<" Which car do you wish to register this person to? "<>car;

for(x = 0; x < 100; x++) {

if(car == Car[x]) {

carInd = x;

break; } }

RegisterCar[na] = carInd; } int PersonCar::Find() { string name; int flag = 0, x;

cout<<" Which person do you want to find?"<>name;

for(x = 0; x < 100; x++) {

if(Person[x] == name) {

flag = 1;

break; } }

if(flag == 1)

return x;

else return -1; }

void PersonCar::CurrentStatus(int x) {

if(x == -1) { cout<<" Person: No one"; cout<<" In car: No one"; }

else {

cout<<" Person: "<

if(RegisterCar[x] != -1)

cout<<" In car: "<

else cout<<" In car: No one"; } }

char PersonCar::Menu() { char choice;

cout<<" Do you want to (P) Make a new Person, (C) Make a new Car, (F) Find a person, (R) Register a Person to a car, or (Q) quit"<>choice; return choice; }

PersonCar :: PersonCar() {

for(int x = 0; x < 100; x++) { Person[x] = ""; Car[x] = ""; RegisterCar[x]= -1; } }

int main() {

PersonCar pc; int index = -1;

pc.CurrentStatus(index);

do {

switch(pc.Menu()) { case 'P': case 'p': pc.CreatePerson(); pc.CurrentStatus(index); break; case 'C': case 'c': pc.CreateCar(); pc.CurrentStatus(index); break; case 'F': case 'f': index = pc.Find();

pc.CurrentStatus(index); break; case 'R': case 'r': pc.Register(index); pc.CurrentStatus(index); break; case 'Q': case 'q': exit(0); default: cout<<" Invalid choice"; } }while(1); }

--------------------------------------------------_END OF CODE---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Problem B: Renaming and linking (20 points) Add two more options to the code from part A:

l - links two people together so they both use the same car. The first name entered is the follower and the second name is the leader. They both use the leader's car. e - rename a car. (This should apply to all people using this car.)

As both link and register car should change the person's car, use the most recent command to determine which car they are in. Thus if a person chooses to link, they should then unregister the current car and only use the link. If a person chooses to register a car, they should remove any links currently active.

If you enter either an invalid person name for the follower of link or an invalid car name for rename, tell them this thing doesn't exist and proceed to the next command. If you enter an invalid leader for the link command (second name), then unlink any current links. You may assume we will not try to link a person to themselves (i.e. command: l then daddy with daddy).

Hint: hope you used pointers... if so this should not require minimal code addition.

Example 1 (user input underlined):

Currently looking at: Person: No one In car: No one 
Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit ... You can also: (e) rename a car or (l) link one person's car to another 
p What is this person's name? daddy 
Currently looking at: Person: No one In car: No one Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit 
... You can also: (e) rename a car or (l) link one person's car to another p What is this person's name? 

kiddo

Currently looking at: Person: No one In car: No one Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit 
... You can also: (e) rename a car or (l) link one person's car to another l Enter person who you want to tag along: 
kiddo Who do you want this person to follow? daddy 
Currently looking at: Person: No one In car: No one Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit 
... You can also: (e) rename a car or (l) link one person's car to another f Which person do you want to find? 

daddy

Currently looking at: Person: daddy In car: No one Do you want to: (p) make a new person, (c) make a new car, (f) find a 
person, (r) register a person to a car, or (q) quit ... You can also: (e) rename a car or (l) link one person's car to another c What is this car's name? helicopter 
Currently looking at: Person: daddy In car: No one Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit 
... You can also: (e) rename a car or (l) link one person's car to another r Which car do you wish to register this person to? 

helicopter

Currently looking at: Person: daddy In car: helicopter Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit 
... You can also: (e) rename a car or (l) link one person's car to another f Which person do you want to find? 

kiddo

Currently looking at: Person: kiddo In car: helicopter Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit 
... You can also: (e) rename a car or (l) link one person's car to another p What is this person's name? 

bestToyEver

Currently looking at: Person: kiddo In car: helicopter Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit 
... You can also: (e) rename a car or (l) link one person's car to another 
l Enter person who you want to tag along: bestToyEver Who do you want this person to follow? kiddo 
Currently looking at: Person: kiddo In car: helicopter Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit 
... You can also: (e) rename a car or (l) link one person's car to another f Which person do you want to find? 

bestToyEver

Currently looking at: Person: bestToyEver In car: helicopter Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit 
... You can also: (e) rename a car or (l) link one person's car to another f Which person do you want to find? 

daddy

Currently looking at: Person: daddy In car: helicopter Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit 
... You can also: (e) rename a car or (l) link one person's car to another c What is this car's name? 

submarine

Currently looking at: Person: daddy In car: helicopter Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit 
... You can also: (e) rename a car or (l) link one person's car to another r 
Which car do you wish to register this person to? submarine 
Currently looking at: Person: daddy In car: submarine Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit 
... You can also: (e) rename a car or (l) link one person's car to another f Which person do you want to find? 

kiddo

Currently looking at: Person: kiddo In car: submarine Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit 
... You can also: (e) rename a car or (l) link one person's car to another e What car do you wish to rename? 
submarine Enter new name: sub 
Currently looking at: Person: kiddo In car: sub Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit 
... You can also: (e) rename a car or (l) link one person's car to another e What car do you wish to rename? 
submarine No such car... 
Currently looking at: Person: kiddo In car: sub Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit 
... You can also: (e) rename a car or (l) link one person's car to another r 
Which car do you wish to register this person to? helicopter 
Currently looking at: Person: kiddo In car: helicopter Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit 
... You can also: (e) rename a car or (l) link one person's car to another e What car do you wish to rename? 
helicopter Enter new name: floppycopter 
Currently looking at: Person: kiddo In car: floppycopter Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit 
... You can also: (e) rename a car or (l) link one person's car to another f Which person do you want to find? 

bestToyEver

Currently looking at: Person: bestToyEver In car: floppycopter Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit 
... You can also: (e) rename a car or (l) link one person's car to another f Which person do you want to find? 

daddy

Currently looking at: Person: daddy In car: sub Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit 
... You can also: (e) rename a car or (l) link one person's car to another q 

Example 2 (user input underlined):

Currently looking at: Person: No one In car: No one Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit 
... You can also: (e) rename a car or (l) link one person's car to another p What is this person's name? 

p1

Currently looking at: Person: No one In car: No one Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit 
... You can also: (e) rename a car or (l) link one person's car to another p What is this person's name? 

p2

Currently looking at: Person: No one In car: No one Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit 
... You can also: (e) rename a car or (l) link one person's car to another f Which person do you want to find? 

p1

Currently looking at: Person: p1 In car: No one Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit 
... You can also: (e) rename a car or (l) link one person's car to another c What is this car's name? 

electric

Currently looking at: Person: p1 In car: No one Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit 
... You can also: (e) rename a car or (l) link one person's car to another r Which car do you wish to register this person to? 

electric

Currently looking at: Person: p1 In car: electric Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit 
... You can also: (e) rename a car or (l) link one person's car to another l Enter person who you want to tag along: 
p2 Who do you want this person to follow? p1 
Currently looking at: Person: p1 In car: electric Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit 
... You can also: (e) rename a car or (l) link one person's car to another f Which person do you want to find? 

p2

Currently looking at: Person: p2 In car: electric Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit 
... You can also: (e) rename a car or (l) link one person's car to another l Enter person who you want to tag along: 
asldfjioh No such person exists... 
Currently looking at: Person: p2 In car: electric Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit 
... You can also: (e) rename a car or (l) link one person's car to another l Enter person who you want to tag along: 
p2 Who do you want this person to follow? asldfoij 
Currently looking at: Person: p2 In car: No one Do you want to: (p) make a new person, (c) make a new car, (f) find a person, (r) register a person to a car, or (q) quit 
... You can also: (e) rename a car or (l) link one person's car to another q 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases DeMYSTiFieD

Authors: Andy Oppel

2nd Edition

0071747990, 978-0071747998

More Books

Students also viewed these Databases questions

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago