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
|
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <fstream>
using namespace std;
void showMenu();
bool testSoldNumbers(int, int, const int);
double showValue(double);
void showValues(int, const int);
double getTotal(double, const int);
int getLowest(int, const int);
double getLowest(double, const int);
int getLowestIndex(double, const int);
double getHighest(double, const int, int);
int main()
{
const int SIZE=10;
double bookCosts[SIZE], bookSales[SIZE], totalSales[SIZE];
int soldNumbers[SIZE], soldNumbers2[SIZE]={4, 6, 8, 10, 3, 5, 7\
, 9, 11, 12};
bool isEqual=true;
ifstream inFile;
ofstream outFile;
int count=0, choice, lowest, lowestIndex, highIndex=0;
double totalSales, sum, lowest, highest;
inFile.open("hw12-1_input.txt");
outFile.open("hw12-1_output.txt");
if(!inFile)
{
cout<<"Could not open input file.\n";
return 1;
}
while(count<SIZE && inFile>>bookCosts[count])
{
count++;
}
do
{
showMenu();
cin>>choice;
if(choice<1 ||choice>9)
{
cout<<"Invalid entry, please choose 1-9;\n";
cin>>choice;
}
switch(choice)
{
case 1:
while(inFile)
for(int i=0;i<SIZE;i++)
cout<<bookCosts[i]<<", ";
break;
case 2:
double bookSales[SIZE];
double tax;
cout<<"Please enter the decimal value of tax:\n";
cin>>tax;
for(int i=0;i<SIZE;i++)
{
bookSales[i]=bookCosts[i]+(bookCosts[i]*tax);
outFile<<bookSales[i];
}
break;
case 3:
for(int i=0;i<SIZE;i++)
cout<<"The sale price for book #"<<(i+1)<<" is "<<bookS\
ale[i]<<endl;
break;
case 4:
for(int i=0;i<SIZE;i++)
{
cout<<"Enter the number of books sold for book #"<<(i+1)<\
<endl;
cin>>soldNumbers[i];
}
break;
case 5:
testSoldNumbers(soldNumbers, soldNumbers2, SIZE);
if(isEqual==true)
cout<<"These two sales are the same"<<endl;
else
cout<<"These two sales were not the same"<<endl;
break;
case 6:
for(int i=0;i<SIZE;i++)
{
totalSales[i]=bookSales[i]*soldNumbers[i];
showValue(totalSales);
}
showValues(soldNumbers, SIZE);
break;
case 7:
getTotal(totalSales, SIZE);
cout<<"The amount of totalSales is $"<<totalSales<<endl;
case 7:
getTotal(totalSales, SIZE);
cout<<"The amount of totalSales is $"<<totalSales<<endl;
getLowest(soldNumbers, SIZE);
cout<<"The lowest number of books sold is "<<lowest<<endl\
;
getLowest(bookCosts, SIZE);
cout<<"The lowest book cost is $"<<lowest<<endl;
getLowestIndex(bookCosts, SIZE);
cout<<"The lowest cost belongs to book #"<<lowestIndex<<e\
ndl;
break;
case 8:
getHighest(bookCosts, SIZE, &highIndex);
default:
break;
}
}while(choice!=9);
return 0;
}
void showMenu()
{
cout<<"Integer Array Menu\n";
cout<<"\t"<<"1. Display all book costs\n";
cout<<"\t"<<"2. Compute sale prices\n";
cout<<"\t"<<"3. Display all sale prices\n";
cout<<"\t"<<"4. Store number of books sold\n";
cout<<"\t"<<"5. Compare two arrays\n";
cout<<"\t"<<"6. Calculate total sales and display\n";
cout<<"\t"<<"7. Find total and min\n";
cout<<"\t"<<"8. Find max\n";
cout<<"\t"<<"9. Quit\n";
cout<<"Enter your choice\n";
}
bool testSoldNumbers(int soldNumbers[], int soldNubers2[], const \
int SIZE)
{
bool isEqual=true;
for(int i=0;i<SIZE;i++)
{
if(soldNumbers[i]!=soldNumbers2[i])
isEqual=false;
else
isEqual=true;
}
return isEqual;
}
void showValue(double totalSales[])
{
int i=0;
cout<<"The total sales price for book #"<<(i+1)<<" is \
$"<<totalSales[i]<<endl;
i++;
}
void showValues(int soldNumbers[], const int SIZE)
{
for(int i=0;i<SIZE;i++)
cout<<"The number of sold books for book #"<<(i+1)<<" is $"<<\
soldNumbers[i]<<endl;
}
double getTotal(double totalSales[], const int SIZE)
{
double sum=0.0;
for(int i=0;i<SIZE;i++)
{
sum+=totalSales[i];
}
return sum;
}
int getLowest(int soldNumbers[], const int SIZE)
{
int lowest=soldNumbers[0];
for(int i=1;i<SIZE;i++)
{
if(soldNumbers[i]<lowest)
lowest=soldNumbers[i];
}
return lowest;
}
double getLowest(double bookCosts[], const int SIZE)
{
int lowest=bookCosts[0];
for(int i=1;i<SIZE;i++)
{
if(bookCosts[i]<lowest)
lowest=bookCosts[i];
}
return lowest;
}
int getLowestIndex(double bookCosts[], const int SIZE)
{
int lowestIndex=0;
for(int i=1;i<SIZE;i++)
{
if(bookCosts[i]<bookCosts[lowestIndex])
lowestIndex=i;
}
return lowestIndex;
}
double getHighest(double bookCosts[], const int SIZE, int &highIn\
dex)
{
double highest=bookCosts[0];
for(int i=1;i<SIZE;i++)
{
if(bookCosts[i]>highest)
{
highest=bookCosts[i];
highIndex=i;
}
}
return highest;
}
|