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

  Reduce the numerator and denominator

Write the function  in C ++ to reduce the numerator and denominator in the Rat class to lowest terms.

  Discussing the competitive advantages

Identify an organization with its management information systems. Prepare a report in discussing the competitive advantages and limitations of the systems. Competitive advantages include the benefits for business, organization, employees, and orga..

  Specifications for the first draft

Submit a first version of your MyClone class. Your MyClone class should have instance variables firstName and lastName. The firstName and lastName instance variables will hold your first and last names. You will demonstrate your understanding of e..

  Consider the following function

Consider the following function:  Which of the following would be the best way to call this function?

  Expected value of the game

A game involves rolling two dice. If the sum of the dice is under 6 your pay off is $5, and if the sum is 6 or over you must pay $5. Find the expected value of the game. Is the game fair? Explain.

  String converter

String Converter: Implement a program that asks the user to input up to 20 strings (stopping when the user inputs 0). Store these strings in a 2-dimensional array. Replace all the characters that are upper-cased to their lower-case equivalent.

  Write two functions to be called by the main program

CSC250 Assignment. Write two functions to be called by the main program. One function is to calculate, in general, a truck's range, that is, the distance the truck can go on one tank of gas (we should probably say fuel. since the bigrig might use ..

  What is the output from the sequence of stack operations

What is the output from the following sequence of stack operations? (please include the code and .exe)

  Write an interactive c program to process the exam scores

Write an interactive C program to process the exam scores for a group of students in a C programming course. Begin by specifying the number of exam scores for each student.

  Write a cgi script that will parse a program

Show that Merge Sort has an O(n lg n) running time by timing the code on the computer - Overview of the program for loop

  Write a program that uses a string array to store a list

The program should allow the user via a menu to add an item to the list, clear the list, and display the list. You may assume that the list will never need to contain more than 10 items.

  Design a deck plan space ship in eclipse

Develop a simple interactive two-dimensional spaceship deck plan editor using OpenGL and GLUT. Your program will enable a user to create and save a deck plan of a hypothetical spaceship comprising the hull walls.

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