Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Topics: Introduction to classes (continued) Overloading function names Abstract data types Friend functions Overloading operators Use the same format for problem and function headings as

Topics:

Introduction to classes (continued)

Overloading function names

Abstract data types

Friend functions

Overloading operators

Use the same format for problem and function headings as assignment 1.

Problem 3.1

Copy the solution from problem 2.2

Make the following additions and changes:

1. Arrange the functions in the order:

* main

* output

* setUp (was setUpCar)

* input

2. Change the output function so it is a member function of the class Car.

3. Change the name of the setUpCar function to setUp and make it a

member function of the class Car, with five parameters specified as

constant reference parameters.

4. Make all the data in the Car class private and make the member

functions public.

5. Do NOT make the input function a member function.

6. Change the parameters of the input function to five reference

parameters corresponding to the five fields in the class.

7. In main define five variables. Pass these variables to the input

function so the input function can set their values.

8. In main define a Car object. This time the Car object will be in the

stack for main, rather than in the heap. Name this object car1.

9. In main call the setUp function and pass the five variables, rather

than calling it from the input function.

10. In main call the output function.

11. Test the program with the same data as was used in assignment 2.

Solution 2.2 Below:

#include #include #include #include

using namespace std;

class car{ public: string reportingmark; int carnumber; string kind; bool loaded; string destination; };

void setUpCar(car &c, string rm, int cn, string kind, bool loaded, string d){ c.reportingmark = rm; c.carnumber = cn; c.kind = kind; c.loaded = loaded; c.destination = d; }

void input(car &c){ string rm; int cn; string kind; bool loaded; string destination; cout << "Enter reporting mark:"; getline(cin,rm); cout << "Enter car number:"; string line; getline(cin,line); cn = atoi(line.c_str()); cout << "Enter kind:"; getline(cin,kind); cout << "Enter loaded(true/false):"; getline(cin,line); if (line == "true") loaded = true; else if (line == "false") loaded = false; if (loaded){ cout << "Enter Destination:"; getline(cin,destination); } else { destination = "NONE"; } setUpCar(c,rm,cn,kind,loaded,destination);

}

void output(car c){ cout << "Reporting Mark:" << c.reportingmark << endl; cout << "Car Number:" << c.carnumber << endl; cout << "Kind:" << c.kind << endl; if (c.loaded) cout << "Loaded:" << "true" << endl; else cout << "Loaded:" << "false" << endl; cout << "Destination:" << c.destination << endl;

}

int main(){

car *c = new car(); input(*c); output(*c); return 0; }

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

MFDBS 91 3rd Symposium On Mathematical Fundamentals Of Database And Knowledge Base Systems Rostock Germany May 6 9 1991

Authors: Bernhard Thalheim ,Janos Demetrovics ,Hans-Detlef Gerhardt

1991st Edition

3540540091, 978-3540540090

More Books

Students also viewed these Databases questions