What would be the decomposition diagram (Used to break program down into compone
ID: 3768222 • Letter: W
Question
What would be the decomposition diagram (Used to break program down into components visually. Can have as many components as needed. Defines functionality that will solve the problem – does NOT define a flow ) of this program:
C++ language
Also the test strategy, test plan, and initial algorithm. When i mean initial algorithm i mean no coding whats so ever. Just the logic.
2015 Fall CIS200-Lab 9-fos/AAH Release date: November 24, 2015 ek Due date: December 1, 2015 root 1, Aorta de Dec 12015 You need to write a program to keep inventory for a hardware store three ways You will write a program to store the inventory in (1) an unsorted linked list and (2) an unsorted array and (3) sorted array. Make the arrays big enough to store 100 records. bubble sor Each record will contain: stevc+ Record # (int), Tool Name (char [20]), Quantity (int) and cost (double) Your program should initialize the array to 100 empty records Then create a menu that allows you to Update a record, Delete a record, List a record, and list All tools (the se to sort Add Then create a menu that allows you to Update a record, Delete a record, List a record, and list ll tols (the ones that are not empty). Aber you add, ear ACher you add reser Start your inventory with the following information uantityCost 57.00 11.99 11.00 79.50 99.99 6.99 21.50 7.50 Record# Name Electric Sander # 7 76 21 17 24 39 56 68 Hammer Jig Saw Lawn mower Power saw Screwdriver Sledge hammer Wrench 18 106 83 34 Perform linear searches to perform the update, delete and list operations. For each operation write to an output file the number of comparisons necessary to perform each operation. After running your program for various inputs write a summary conclusion on the efficiency of performing the perations in the three waysExplanation / Answer
#include <iostream>
#include <fstream>
#include <iomanip>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <windows.h>
using namespace std;
typedef struct _tooldata
{
int toolNum;
char toolName[128];
int quantity;
double cost;
} toolData;
void textFile(fstream &readFromFile);
int enterChoice();
void updateRecord(fstream &updateFile);
void newRecord(fstream &insertInFile);
void deleteRecord(fstream &deleteFromFile);
void outputLine(ostream &output, toolData tool);
void gotoxy(int x, int y)
{
COORD ord;
ord.X = x;
ord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), ord);
}
void clrscr()
{
system("CLS");
}
static char FILENAME[] = "tools.dat";
void CreateDataFile()
{
fstream testFileExists(FILENAME, ios::in | ios::out);
if (!testFileExists)
{
ofstream outtools(FILENAME);
toolData *data = new toolData();
strcpy(data->toolName, "");
data->quantity = 0;
data->cost = 0.0;
data->toolNum = 0;
for(int i = 0; i < 100; i++)
outtools.write((char*)data, sizeof(*data));
outtools.close();
}
else
testFileExists.close();
}
int main()
{
CreateDataFile();
fstream inOuttools(FILENAME, ios::in | ios::out);
inOuttools.seekg(0,ios::end);
long location = inOuttools.tellg();
cout << "Size of hardware.dat = " << location;
int choice;
while ( ( choice = enterChoice() ) != 5 ) {
switch (choice)
{
case 1: textFile(inOuttools); break;
case 2: updateRecord(inOuttools); break;
case 3: newRecord(inOuttools); break;
case 4: deleteRecord(inOuttools); break;
default: cerr << "Incorrect choice" << endl; break;
}
inOuttools.clear(); // resets end-of-file indicator
}
clrscr();
return 0;
}
// Prompt for and input menu choice
int enterChoice(void)
{
cout << endl << "Enter your choice" << endl
<< "1. stored a formatted text file of accounts" << endl
<< " called hardware.dat for printing" << endl
<< "2. update inventory" << endl
<< "3. add a new item" << endl
<< "4. delete an item" << endl
<< "5. end program" << endl << "? ";
int menuChoice;
cin >> menuChoice;
return menuChoice;
}
// Create a random access data file called <tools.dat>
void makeDirectAccessFile(fstream &inOuttools)
{
toolData blanktool = {0, "", 0, 0.0};
for (int i = 1; i <= 100; i++)
inOuttools.write((char *)&blanktool, sizeof(toolData));
cout << endl << endl
<< "A direct access file called <hardware.dat> has been " << endl
<< "created with four fields initialized as follows:"
<< endl << endl
<< " toolNum = 0" << endl
<< " toolName[15] = """ << endl
<< " long quantity = """ << endl
<< " cost = 0.0" << endl;
cout << endl << "Press any key to return to the menu." << endl << endl;
getch();
}
void textFile(fstream &readFromFile)
{
ofstream outPrintFile("print.txt", ios::out);
if (!outPrintFile) {
cerr << "File could not be opened." << endl;
exit(1);
}
clrscr();
cout << setiosflags(ios::left) << setw(6) << "Tool"
<< setw(16) << "Tool Name" << setw(11) << "Quantity"
<< setiosflags(ios::right) << setw(10) << "Cost" << endl;
outPrintFile << setiosflags(ios::left) << setw(6) << "Tool"
<< setw(16) << "Tool Name" << setw(11) << "Quantity"
<< setiosflags(ios::right) << setw(10) << "Cost" << endl;
readFromFile.seekg(0);
toolData tool;
readFromFile.read((char *)&tool, sizeof(toolData));
while (!readFromFile.eof()) {
if (tool.toolNum != 0) {
outputLine(outPrintFile, tool);
outputLine(cout, tool);
}
readFromFile.read((char *)&tool, sizeof(toolData));
}
}
void updateRecord(fstream &updateFile)
{
int account;
clrscr();
do {
cout << "Enter inventory number to update (1 - 100): ";
cin >> account;
} while (account < 1 || account > 100);
updateFile.seekg((account - 1) * sizeof(toolData));
toolData tool;
updateFile.read((char *)&tool, sizeof(toolData));
if (tool.toolNum != 0) {
outputLine(cout, tool);
cout << endl << "Enter charge (+) or payment (-): ";
float transaction;
cin >> transaction;
tool.cost += transaction;
outputLine(cout, tool);
updateFile.seekp((account - 1) * sizeof(toolData));
updateFile.write((char *)&tool, sizeof(toolData));
}
else
cerr << "Acount #" << account << " has no information." << endl;
}
void newRecord(fstream &insertInFile)
{
char text[80];
clrscr();
cout << "Enter new item number (1 - 100): ";
int account;
cin >> account;
insertInFile.seekg((account - 1) * sizeof(toolData));
toolData tool;
insertInFile.read((char *)&tool, sizeof(toolData));
if (tool.toolNum == 0)
{
cout << "Enter the tool name and press <ENTER>: ";
cin.getline(text,80);
cin.getline(text,80);
if ( strlen(text) > 14)
{
strncpy (tool.toolName, text, 14);
tool.toolName[14] = '';
cout << "Name is too long. It has been shortened to "
<< tool.toolName << "." << endl;
}
else
{
strcpy(tool.toolName, text);
tool.toolName[14] = '';
}
cout << "Enter the quantity and press <ENTER>: ";
cin >> tool.quantity;
cout << "Enter the cost as a decimal value and press <ENTER>: ";
cin >> tool.cost;
tool.toolNum = account;
insertInFile.seekp((account - 1) * sizeof(toolData));
insertInFile.write((char *)&tool, sizeof(toolData));
}
else
cerr << "Account #" << account
<< " already contains information." << endl;
}
void deleteRecord(fstream &deleteFromFile)
{
clrscr();
cout << "Enter account number to delete (1 - 100): ";
int account;
cin >> account;
deleteFromFile.seekg((account - 1) * sizeof(toolData));
toolData tool;
deleteFromFile.read((char *)&tool, sizeof(toolData));
if (tool.toolNum != 0) {
toolData blanktool = {0, "", 0, 0};
deleteFromFile.seekp((account - 1) * sizeof(toolData));
deleteFromFile.write((char *)&blanktool, sizeof(toolData));
cout << setiosflags(ios::left) << setw(6) << "tool"
<< setw(16) << "Last Name" << setw(11) << "First Name"
<< setiosflags(ios::right) << setw(10) << "cost" << endl;
outputLine(cout, tool);
cout << "Account #" << account << " deleted." << endl;
}
else
cout << "Account #" << account << " is empty." << endl;
}
void outputLine(ostream &output, toolData tool)
{
output << setiosflags(ios::left) << setw(6) << tool.toolNum
<< setw(16) << tool.toolName << setw(11) << tool.quantity
<< setiosflags(ios::fixed | ios::showpoint | ios::right)
<< setw(10) << setprecision(2) << tool.cost << endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.