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
|
#include <fstream>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <stdlib.h>
using namespace std;
const int MAX_SIZE = 50;
const int NAME_SIZE = 30;
const int COLUMNROW = 4;
typedef char STRING_30[NAME_SIZE];
typedef STRING_30 LIST_S30[MAX_SIZE];
typedef STRING_30 LIST_COL[COLUMNROW];
typedef int LIST_I[MAX_SIZE];
typedef float LIST_F[MAX_SIZE];
//******************************* main ********************************
int main(int argc, char *argv[])
{
int choice;
char drive[2],
disk_file[15],
file[9];
ofstream outfile;
// input section
system ("cls"); // clear the screen
ifstream inf;
inf.open("input.txt");
LIST_S30 lastname, firstname;
LIST_I daysofrent;
LIST_F balancedue;
LIST_COL headers;
int listcount = 0;
while ( listcount <= 10)
{
if (listcount == 0)
{
inf >> headers[listcount] >> headers[listcount] >> headers[listcount] >> headers[listcount];
}
else
{
inf >> lastname[listcount-1] >> firstname[listcount-1] >> daysofrent[listcount-1] >> balancedue[listcount-1];
}
listcount ++;
}
listcount=0;
while ( listcount < 10)
{
cout << "Record " << lastname[listcount] << ", " << firstname[listcount];
cout << " " << daysofrent[listcount] << " " << balancedue[listcount] << endl;
listcount ++;
}
system ("PAUSE");
// process section
// remove this comment ans place your process statements here.
// output section
system ("cls");
cout << "Output to console (1) or disk file (2): ";
cin >> choice;
if ( choice == 1 )
{
system ("cls");
outfile.open("con");
}
else //routine allows interactive entry of external file name
{
cout << "Which drive: a, b, c, d, e, or f ? ";
cin >> drive;
strcpy(disk_file, drive);
strcat(disk_file, ":");
cout << "Enter a results file name: ";
cin >> file;
strcat(disk_file, file);
strcat(disk_file, ".dta");
outfile.open(disk_file);
}
outfile << setiosflags(ios::showpoint | ios::fixed) << setprecision(2);
outfile << "LastName" << setw (5) << " " << "FirstName" << setw(5) << " " << "DaysofRental" << setw(5) << " " << "BalanceDue" << endl;
while ( listcount <= 10)
{
if (listcount == 0)
{
inf >> headers[listcount] >> headers[listcount] >> headers[listcount] >> headers[listcount];
}
else
{
inf >> lastname[listcount-1] >> firstname[listcount-1] >> daysofrent[listcount-1] >> balancedue[listcount-1];
}
listcount ++;
}
listcount=0;
while ( listcount < 10)
{
cout << lastname[listcount] << ", " << firstname[listcount];
cout << " " << daysofrent[listcount] << " " << balancedue[listcount] << endl;
listcount ++;
}
outfile.close();
cout << endl << endl; // provides blank line before pause display message
system ("pause");
return 0;
}
|