Change the implementation of the stringofcars class

Assignment Help C/C++ Programming
Reference no: EM131152902

Assignment 6

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

Problem 6.1

Copy the solution from problem 5.2.

You will change the implementation of the StringOfCars class, but keep the public interface. This implementation will use a linked list, rather than an array or vector to hold the cars.

Keep all the public function prototypes in the StringOfCars.

Discard all the private data and the implementation of the functions; you will rebuild all of these.

Do not change anything outside the StringOfCars class.

Use the cardata5.txt file for your input.

Build a new class called Node:

You will build the linked list using Node objects, linked together to make a list.

In the private data of the Node class put two pointers:

One with type Node * and name next, which will point to the next node in the linked list,

The second with type Car* and name data, which will point to the Car data associated with this node.

Also in the private area create a default constructor that sets the next and data pointers to zero. Because the constructor is private, only friends can use this class.

In the public area of the Node class, make StringOfCars a friend class.

The order of the following three things is important:

1. Declare the StringOfCars class with: class StringOfCars;
2. The Node class
3. The StringOfCars class

This is needed because the Node class uses the StringOfCars and the StringOfCars class uses the Node class.

In the StringOfCars class implementation:

Replace the private data with two pointers of type Node *, and nothing else. Name these two pointers head and tail.

Change the StringOfCars default constructor to set the head and tail pointers to zero.

Rebuild the push function, with the same function heading.

Declare a local pointer variable of type Car * named currentCarPtr.

Declare a local pointer variable of type Node * named currentNodePtr.

Use new to get space in the heap for a Node and save the address of the space in the heap in currentNodePtr

Use new get space in the heap for a new Car that is a copy of the car parameter of the push function and save the address of the space in the heap in currentCarPtr

Set the data pointer in this new Node object to point to the new Car object.

If the head pointer is zero

set the head and the tail pointer to the value of currentNodePtr

else

set the next pointer of the Node object pointed to by the tail pointer to the value of currentNodePtr

set the next pointer to the value of the currentNodePtr

Do not write a pop function.

Rebuild the output function, with the same function heading.

Declare a local pointer variable of type Node * named currentNodePtr - it will point to the Node you are currently working on.

if the head pointer is zero
print: NO cars
else
set the currentNodePointer to the value of the head pointer
while the currentNodePointer is not zero
print the Car pointed to by the currentNodePointer
set the currentNodePtr to the next pointer in the Node pointed to by
the currentNodePtr, which now makes the next Node the current Node
Rebuild the copy construtor.

Declare a local pointer variable of type Node * named currentNodePtr - it will point to the Node in the oldStringOfCars that you are currently working on.

Set the head and tail pointers in the StringOfCars being constructed to zero.

If the oldStringOfCars head pointer is not zero:

loop while the currentNodePointer is not zero,

push the Car pointed to by the data pointer in the current Node, which is pointed to by the currentNodePointer.

set the currentNodePtr to the next pointer in the currentNodePtr so we now make the next Node the current Node

Use the same tests as in problem 5.2.

Attachment:- Attachments.rar

Reference no: EM131152902

Questions Cloud

Describe the four factors that directly influence individual : Describe the four factors that directly influence individual behavior and performance (provided by McShane and Von Glinow, 2013), and explain a scenario or real-life example for two of the four factors
Evaluate the normal stress and shear stress : Determine the normal stress and shear stress acting on the inclined plane AB . Solve the problem using the stress transformation equations. Show the results on the sectional element.
Determine the normal stress and shear stress acting : Determine the normal stress and shear stress acting on the inclined plane AB . Solve the problem using the method of equilibrium described in Sec. 9.1 .
How has pmmm brought success to both sap and petrotrin : How has PMMM brought success to both SAP and Petrotrin's overall enterprise? Use current financial, operational, and strategic news to support the article details for either SAP or Petrotrin to describe their recent results
Change the implementation of the stringofcars class : You will change the implementation of the StringOfCars class, but keep the public interface. This implementation will use a linked list, rather than an array or vector to hold the cars.
Find the equivalent state of stress on an element : Determine the equivalent state of stress on an element at the same point that represents the principal stresses at the point. Also, find the corresponding orientation of the element with respect to the element shown.
Develop the limitations and methods to solve given problem : Develop the limitations and methods to solve to what is written in the problem and scope: - the limitations are:- the advisor himself- university, the administration might ntbe interested in hiring new advisors.
What is the companymission statement : What is the company's mission statement? What is the company's vision statement? What role do these have on the way the business operates? Do the company's actions seem to align to their vision and mission statements
Are these concepts tools and methodologies universal : Are these concepts, tools and methodologies universal? That is, do they apply to any institutions? For example, do they apply to the military? Or to City Hall? If not, should they

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Sum of all non-inherited data members

show on the console the sum of all non-inherited data members of every instance in the program by Display() function

  Provide public member functions that perform the given task

Provide public member functions that perform the given tasks setComplex function to set complex number to set the real part and imaginary part of the complex number

  Define how stack template works

Even though the program runs correctly, there is a memory problem somewhere in the program and I can't figure out what I have done wrong.

  Write a program that accepts two real numbers

Write a program that accepts two real numbers from a user and a select code. If the entered select code is 1, have the program add the two previously entered numbers and display the result

  Creating class perform computation and display results

Create a class named Numbers whose Main() method holds two integer variables. Assign values to the variables. Within the class, create two methods, Sum () and Difference (), that compute the sum of and difference between the values of the two vari..

  Themartinweight loss clinic maintains two patient files

TheMartinWeight Loss Clinic maintains two patient files—one for male clients and one for female clients. Each record contains the name of a patient and current total weight loss in pounds. Each file is in descending weight loss order. Design the logi..

  Explain conditional expressions in the c language

What if the initial value assigned to a is 13, not 3? What happens with this code and why does this occur? What does this tell you about setting up conditional expressions in the C language?

  What output is produced by the following program

What output is produced by the following program?

  The owner of a hardware store and need to keep an inventory

You are the owner of a hardware store and need to keep an inventory that can tell you what tools you have, how many you have and the cost of each one. Write a C program to create a file named storage.dat and write the data shown in the Table 1 into t..

  Write cpp program that is menu-driven that allows for choice

Write a C++ program that is menu-driven that allows for the following menu choices: Load an exam: Loading an exam should prompt the user for an exam file.

  Write a program for a college admissions office

Write a program for a college admissions office. The user enters a numeric high school grade point average (Ex 3.2), and an admission test score. Print the message "Accept" if the student meets either of the subsequent requirements:

  Fill up the tables

Fill up the tables and show ALL the steps required to solve each problem below. You must convert the entire IP address to binary.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd