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
|
/*
Author: James Krause
UserId #: c1010b27
Creation Date: 04/26/2012
Modification Date: 04/26/2012
Course: CISP 1010 P02
File name: lab8.cpp
Inputs: cpu, os, quantity, price, computer.
Ouputs: cout
Formulas: none
Test Data: Use different Processors, different operating systems, and also make sure that it continues to add to previous stock counts
Purpose: To gain familiarity with structures and classes.
*/
#include <iostream>
#include <string>
using namespace std;
// GLOBAL DECLARATION
const int MAX_COMPUTERS=5;
// class blue print for inventory (CPU type, OS, Quantity, Price)
class Inventory
{
public:
static void orderPrice(const int MAX_COMPUTERS, double price[]); // Declare function to order arrays by price.
string cpu; // Processor
string os; // Operating System
int quantity; // How many in stock
double price[MAX_COMPUTERS]; // Price of computer
};
void get_data (Inventory& computer);
// accepts one computer at a time and stores values into the member variables of the inventory structure
int main ()
{
// Declare variables
Inventory computer;
int totalInventory = 0;
double totalPrice = 0.00;
double price[MAX_COMPUTERS];
for (int i=0; i <= MAX_COMPUTERS; i++)
{
get_data(computer);
totalInventory += computer.quantity; // Add new computer stock to total stock
totalPrice += computer.quantity * computer.price[i]; // Add new computer price to total price
cout << "Processor: " << computer.cpu << endl;
cout << "Operating System: " << computer.os << endl;
cout << "In Stock: " << computer.quantity << endl;
cout << "Price: " << computer.price[i] << endl;
cout << "Total inventory: " << totalInventory << endl;
cout << "Total price: " << totalPrice << endl;
}
Inventory::orderPrice(MAX_COMPUTERS, price);
cout << "Total inventory: " << totalInventory << endl;
cout << "Total price: " << totalPrice << endl;
return 0;
}
void get_data (Inventory& computer)
{
cout << "Enter Processor Model: ";
cin >> computer.cpu;
cout << "Enter Operating System: ";
cin >> computer.os;
cout << "Enter stock counts: ";
cin >> computer.quantity;
cout << "Enter Price: ";
cin >> computer.price[MAX_COMPUTERS];
}
void Inventory::orderPrice(const int MAX_COMPUTERS, double price[])
{
int i, j, flag = 1; // set flag to 1 to start first pass
double temp; // holding variable
for(i = 1; (i <= MAX_COMPUTERS) && flag; i++)
{
flag = 0;
for (j=0; j < (MAX_COMPUTERS -1); j++)
{
if (price[j+1] < price[j])
{
temp = price[j];
price[j] = price[j+1];
price[j+1] = temp;
flag = 1;
}
}
}
return;
}
|