you are to write a program that will sum up inventory counts and report the total. the inventory is represented by a three digit inventory number and a count of the items. sample/test data is given below to test your program, but the real data may be more or less items than shown.
there exists a problem with the data. two different inventories have been mixed up in the list. The inventory number and the count still match up though. You need to separate out the two inventories and get a count for each one(ie inventory ONE and inventory TWO). The R&D department has discovered that the teo inventories can be distinguished by digits in the inventory number. If the digits in the inventory number sum up to be less than or equal to 13, then those items belong to inventory ONE. The others to inventory TWO.
Separate and compute sums for each of the two inventories and generate a total inventory count for each one. Print out each item in the inventory, the total number of items found in each inventory, total counts and the average for eah of the two intentories. Youhave to write to two output files. You are given sample data below.
The input files for testing your program are in two different files. The first file has the item number. The second file has the counts. Item file: inventoryItemNbr.txt Count file: inventoryCount.txt.
Below is sample of each file:
item 382, 123, 965, 432, 823, 872, 734, 882, 117, 632, 664, 841, 149, 681, 616, 915, 323, 448, 552, 662, 811
count 20, 40, 109, 45, 341, 51, 513, 43, 45, 673, 982, 8, 134, 155, 632, 103, 21, 15, 49, 134
example output for inventory one
382 20
123 40
Inventory two
965 109 872 51
etc
cannot use arrays or classes. use functions, if, else, while. use <fstream><iomanip> <iostream>. THis is for basic input, please nothing fancy. I'm learning and going bald in the process. THank you to anyone who responds.
With this code, I am having an issue with my infiles. Each time I run my code, I receive my error message assigned to the infile. I'm unable to figure out why.
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
|
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
ofstream Inventory1;
Inventory1.open("Inv1.out");
ofstream Inventory2;
Inventory2.open("Inv2.out");
ifstream ItemInvNumber;
ItemInvNumber.open("ItemNumber.txt");
if(!ItemInvNumber)
{
cout<<" Error opening ItemNumber.txt "<<ItemInvNumber<<endl;
return 0;
}
ifstream InvCnt;
InvCnt.open("InventoryCount.txt");
if(!InvCnt)
{
cout<<" Error opening InventoryCount.txt "<<InvCnt<<endl;
return 0;
}
else
{
int item1, item2,digit,
totalInvOne=0,
totalInvTwo=0,
cnt1=0,cnt2=0,
sum=0,totcnt;
float avg1,
avg2;
string add, invno;
while(digit!=0)
{
sum+=(digit%10);
digit/=10;
}
return(sum);
{
Inventory1<<" Inventory ONE "<<endl;
Inventory2<<" Inventory TWO "<<endl;
if(sum<=13)
{
item1++;
cnt1+=totcnt;
Inventory1<<invno<<endl;
}
else
{
item2++;
cnt2+=totcnt;
Inventory2<<invno<<endl;
}
avg1=cnt1/item1;
avg2=cnt2/item2;
Inventory1<<" Total Number of Items: "<<item1<<endl<<"Total Count: "<<cnt1<<endl<< "Average: "<<avg1<<endl
<<setprecision(3)<<fixed<<right;
Inventory2<<" Total Number of Items: "<<item2<<endl<<"Total Count: "<<cnt2<<endl<< "Average: "<<avg2<<endl
<<setprecision(3)<<fixed<<right;
Inventory1.close();
Inventory2.close();
ItemInvNumber.close();
InvCnt.close();
return 0;
}
}
|