Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In c++ please code to edit // COMMONLY NEEDED DIRECTIVES AND DECLARATIONS #include using namespace std; // CLASS DECLARATION class DB { public: void store

In c++ please

image text in transcribed

code to edit

// COMMONLY NEEDED DIRECTIVES AND DECLARATIONS

#include

using namespace std;

// CLASS DECLARATION

class DB

{

public:

void store ();

void viewChronologically ();

void sortbyPartID ();

void viewbyPartID ();

private:

class Part // This "public class" could also be a "struct" instead.

{

public:

int ID;

float Price;

int Quantity;

Part (void) {};

Part (int Partnum, float rate, int quant); // DO: Initialize appropriately.

// DO: Can you ALSO think of initializing it in a different way?

void store ()

{

// DO: Fill in prompts and input statements as indicated by the

// sample output:

};

void print () {cout

Inventory = "

};

Part inv[3];

Part* IDp[3];

void swap (Part * &, Part * &);

};

// CLASS DEFINITION

void DB::store ()

{

cout

for (int i = 0; i

{

cout

inv[i].store();

IDp[i] = &inv[i];

};

// DO: Print a thank you message after storing as indicated in the

// sample output:

};

void DB::viewChronologically ()

{

cout

for (int i = 0; i

};

// DO: Fill in the definition for the swap method in the DB class:

void DB::swap (Part * & a, Part * & b)

{

};

void DB::sortbyPartID ()

{

if (IDp[0]->ID > IDp[1]->ID) swap (IDp[0], IDp[1]);

if (IDp[1]->ID > IDp[2]->ID)

{

swap (IDp[1], IDp[2]);

if (IDp[0]->ID > IDp[1]->ID) swap (IDp[0], IDp[1]);

}

};

void DB::viewbyPartID ()

{

// DO: Fill in based on sample output:

};

int main ()

{

DB DB1;

DB1.store();

DB1.sortbyPartID();

DB1.viewbyPartID();

DB1.viewChronologically();

cout

exit (0);

};

Part A: In this exercise, for part A, you will first create a very simple inventory database" class that we call Tiny Database (or TDB). This database can store three part objects, each with an ID, price, and quantity. It can also display information about the objects as entered in chronological order, and also create a view sorted by the part ID, and display it, too. You are supplied with a decent amount of start-up code in the file TDB-assigned.cpp. that might put you at ease. However, the code is somewhat incomplete, and your job is to complete the code, so it can produce "Part A" output, which is also supplied to you (TDB-A-out.txt). Look in the code file for the word "DO" to find where and what you need to do. Complete the code and demo that the output matches what is expected (i.e., with TDB-A-out.txt). Part B: In this part, you will modify the code from part A to enhance the capability of the program to also create a view sorted separately by Price, and to display the view. It is important that in doing this neither the chronological view nor the view sorted by ID is messed up; in other words, you shouldn't have to restore them, by ensuring that they are not disturbed in the first place. Your modified program should produce the output shown in the Part B output file that is supplied to you (TDB-B-out.txt). You should start on this task by adding the following lines of code before outputting the final goodbye message at the end of the main function: /* Part B */ DB1.sortbyPrice (); /* Part B */ DB1.viewbyPrice(); /* Part B */ DB1.viewby PartID(); /* Part B */ DB1.viewChronologically()

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

Step: 3

blur-text-image

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

Database Management Systems Designing And Building Business Applications

Authors: Gerald V. Post

1st Edition

0072898933, 978-0072898934

More Books

Students also viewed these Databases questions