#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
const int maxs = 50;
void initem(int id[], string name[], int unitsold[], double price[], int &nums, int &nump)
{
int i;
for(i=0; i<maxs; i++)
{
id[i] = 0;
unitsold[i] = 0;
price [i] = 0;
name[i] = "Brock Sampson";
}
nums = 0;
nump = 0;
}
void printtitles()
{
cout << "Print Titles Reached";
}
void printline(char ch, int nums, ofstream &outf)
{
int i;
for (i=1; i<nums; i++) outf << ch;
outf << endl;
}
void readem(int id[], string name[], int usold[], double uprice[], int &nums, int &nump)
{
int i;
ifstream inf;
inf.open("inf.dat");
i=0;
nump=0;
while(!inf.eof())
{
inf >> id[i] >> name[i] >> usold[i] >> uprice[i];
i++;
nump++;
}
nums = i;
}
void calcem()
{
cout << "Calc Items Reached" << endl;
}
void swapem(string &a, string &b)
{
string temp;
temp=a;
a=b;
b=temp;
}
void sortem(string name[], int id[], int usold[], int uprice[], int &nums)
{
int i, j;
for(j=0; j<nums-1; j++)
for(i=0; i<nums-1; i++)
if(name[i] > name[i+1])
{
swapem(name[i], name[i+1]);
swapem(id[i], id[i+1]);
swapem(usold[i], usold[i+1]);
swapem(uprice[i], uprice[i+1]);
}
}
void printem(int id[], string name[], int unitsold[], double price[], int &nums, ofstream &outf)
{
int i;
for(i=0; i<nums; i++)
{
outf << setw(5) << left << id[i] << setw(10) << left << name[i] << setw(4) << right
<< unitsold[i] << setw(7) << price[i] << endl;
}
}
void main()
{
int id[maxs], usold[maxs];
int nums, nump;
double uprice[maxs];
string name[maxs];
ofstream outf;
outf.open ("outf.out");
readem(id, name, usold, uprice, nums, nump);
calcem();
sortem(name, id, usold, uprice, nums);
printem(id, name, usold, uprice, nums, outf);
cout << nump << endl; |