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

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

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