1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
|
/*
Title: program4.cpp
Author: Zach Coombs
Date: April 11, 2011
Purpose: Manage inventory of supercars using a menu-driven
program that keeps track of how many cars are in inventory, the type of vehicle,
and asking price. It will then write the stored information to a file.
*/
#include<iostream>
#include<iomanip>
#include<string>
#include<fstream>
using namespace std;
// Function prototypes
int loadVehicles(int, int[], string[], float[], float[]);
void addCar(int, int[], string[], float[], float[]);
void calculateTotals(int);
void calculatePrice(float[], float[], float, float[]);
void writeVehicles();
int main()
{
const int hourlyWage = 10;
const int arraySize = 100; // Array size
int numItems;
int carType[arraySize]; // Array with 100 elements
string carName[arraySize]; // Character string with 100 elements
float costMaterials[arraySize];
float numHours[arraySize];
float askingPrice[arraySize];
bool goAgain = true;
int menuChoice;
loadVehicles(numItems, carType, carName, costMaterials, numHours);
while(goAgain == true)
{
// Menu
cout << "------------------------------------------------------";
cout << endl << endl;
cout << "Vehicle Inventory Management Program" << endl;
cout << "\t1.\t Add a car to inventory" << endl;
cout << "\t2.\t Calculate totals for coupes" << endl;
cout << "\t3.\t Calculate totals for roadsters" << endl;
cout << "\t4.\t Calculate totals for sedans" << endl;
cout << "\t5.\t Calculate totals for all cars" << endl;
cout << "\t6.\t Quit the program" << endl;
cout << "\t\t Choose 1-6: ";
cin >> menuChoice;
cout << endl;
switch(menuChoice)
{
case 1: addCar(numItems, carType, carName, costMaterials, numHours); cout << endl;
break;
case 2: //calculateTotals(menuChoice); cout << endl;
break;
case 3: //calculateTotals(menuChoice); cout << endl;
break;
case 4: //calculateTotals(menuChoice); cout << endl;
break;
case 5: //calculatePrice(askingPrice, numHours, hourlyWage, costMaterials); cout << endl;
break;
case 6: //writeVehicles();
goAgain = false;
break;
default: cout << "That is an invalid choice" << endl;
}
} // End while loop
system("PAUSE");
return 0;
} // End main
// Function Definitions
int loadVehicles(int numItems, int carType[], string carName[], float costMaterials[], float numHours[])
{
numItems = 0;
int count;
ifstream inputFile;
inputFile.open("cars.txt");
for (count = 0; count < 100; count ++)
{
inputFile >> carType[count] >> carName[count] >> costMaterials[count] >> numHours[count];
}
inputFile.close();
// Test
cout << "The vehicles are: ";
for (count = 0; count < 100; count ++)
{
cout << carType[count] <<" "<< carName[count] <<" "<< costMaterials[count] <<" "<< numHours[count];
cout << endl << endl;
}
count = numItems;
cout << numItems << endl << endl;
return numItems;
}
//*******************************************************************
// addCar
//
// task: This function is called when the user wants to add a new vehicle to inventory.
// The function will accept the current number of items plus four arrays as parameters and return the new
// number of items. The function will only add a new jewelry item if there are less than 100 items in the
// arrays (do not want to go out of bounds).
// data in:
// data out:
//
//*******************************************************************
void addCar(int numItems, int carType, string carName[], float costMaterials[], float numHours[])
{
if (numItems != 100)
{
int x = 0;
cout << "Pick from the following vehicle styles:" << endl;
cout << "\t1. Coupes" << endl;
cout << "\t2. Roadsters" << endl;
cout << "\t3. Sedans" << endl;
cout << "\tChoose 1, 2, or 3: ";
cin >> carType;
if (carType == 1)
{
cout << "Enter the name of the car" << endl;
getline(cin, carName[x]);
}
else
cout << "You can only enter a maximum of 100 items" << endl << endl;
}
}
//*******************************************************************
// calculateTotals
//
// task: This function is called when the user wants to view how many items are in the different
// car types or all together and see how much in total the materials cost and
// asking price is for inventoryitems. There are quite a few parameters accepted
// in this function. First, an integer representing what kind of table will be
// printed out (1=coupe, 2=roadsters, 3=sedans, -1 = all). Then, an integer
// representing how many total items are in the arrays. Then all five arrays that
// were defined in main.
// data in:
// data out:
//
//*******************************************************************
/*void calculateTotals(int menuChoice)
{
if (menuChoice == 2)
{
cout << "Total Coupes in Inventory:" << endl << endl;
cout << "TYPE\t\t\t\tNAME\tCOST\tLABOR\tPRICE" << endl;
}
else if (menuChoice == 3)
{
cout << "Total Roadsters in Inventory:" << endl << endl;
cout << "TYPE\t\t\t\tNAME\tCOST\tLABOR\tPRICE" << endl;
}
else if (menuChoice == 4)
{
cout << "Total Sedans in Inventory:" << endl << endl;
cout << "TYPE\t\t\t\tNAME\tCOST\tLABOR\tPRICE" << endl;
}
}
//*******************************************************************
// calculatePrice
//
// task: This function calculates the asking price of a vehicle based on
// the cost of the materials and the hours put in making the item, which is sent
// in to this function as arguments. The function does the calculation and then
// returns the asking price as a floating point value.
// data in:
// data out:
//
//*******************************************************************
void calculatePrice(float askingPrice[], float numHours[], float hourlyWage, float costMaterials[])
{
int x = 0;
askingPrice[x] = numHours[x] * hourlyWage + costMaterials[x];
cout << "Total vehicles in Inventory:" << endl << endl;
cout << "TYPE\t\t\t\tNAME MAT.COST LABOR HRS\tPRICE" << endl;
}
//*******************************************************************
// writeVehicles
//
// task: This function will write out all the elements in four arrays
// (jewelryType, jewelryName, costMaterials, numHours) to the jewelry.txt file.
// Each element in the arrays is on one line of the text file.
// data in:
// data out:
//
//*******************************************************************
void writeVehicles()
{
cout << "Thanks for using the Supercar Inventory Management Program." << endl << endl;
}
*/
|