Comments are available to members only. Sign up or Log in to view these comments.
Main Topics
Browse All TopicsIm trying to left justify the output.. The olny thing that does not justify is the firstline.. Im trying to use the cout.setf(ios::left) where i read in file. What am i doing wrong.
Report for: Data.txt
1 1002 Mc Carthy Tom d 1952 51
2 1004 Smith Sara r 1980 23
3 1005 Harrison Ron C 1966 37
4 6000 Stone Sharon D 1950 53
5 8000 La Berta Cathy R 1952 51
#if !defined(microsoft)
#include<stdlib.h>
#define cls() system("cls");
#endif
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<string.h>
#include<ctype.h>
#include<fstream.h>
#include<windows.h>
#include "color.h"
#include "fileutil.cpp"
#include "voter.h"
#include "date.h"
int DisplayMenu(int);
void AddVoter(voter voterlist[], int&);
void EditVoter(voter voterlist[], int);
void PrintReport( voter voterlist[], int);
void SaveFile(voter voterlist[], ofstream&, int);
void SaveReport(voter voterlist[], ofstream&, int);
void GetData( voter voterlist[], int&, ifstream&, int&);
void DeleteVoter(voter voterlist[], int& size);
void main()
{
const int arraysize = 100;
int size = arraysize;
int error = 0;
int choice = 0;
//Array declaration
voter voterlist[arraysize];
//Read and write declaration
ifstream infile;
ofstream outfile;
//Calling funtion to get data to build array
GetData (voterlist, error, infile, size);
cls();
//
while (choice <=8)
{
choice = DisplayMenu(choice);
if (choice == 1)
{
PrintReport(voterlist, size);
getche();
}
else if
(choice == 2)
SaveReport(voterlist, outfile, size);
else if
(choice == 3)
AddVoter(voterlist, size);
else if
(choice == 4)
EditVoter(voterlist, size);
else if
(choice == 5)
SaveFile(voterlist, outfile, size);
else if
(choice == 6)
DeleteVoter(voterlist, size);
else if
(choice == 7)
sortid(voterlist, size);
else if
(choice == 8)
sortArray ( voterlist, size);
}
cls();
cout << "Thanks for using program"
<< endl;
getche();
}
int DisplayMenu(int choice)
{
cls();
cout << setw(25) << "\n ========== Menu Selection Screen ============= \n";
cout << setw(25) << "\n [1] Display voters to display ";
cout << setw(25) << "\n [2] Save Report to Disk ";
cout << setw(25) << "\n [3] Add New Voter to List ";
cout << setw(25) << "\n [4] Change Party of Voter ";
cout << setw(25) << "\n [5] Make Backup File ";
cout << setw(25) << "\n [6] Delete Voter ";
cout << setw(25) << "\n [7] Sort by Voter Id ";
cout << setw(25) << "\n [8] Sort by Last Name ";
cout << setw(25) << "\n [9] Exit Program \n";
cout << setw(25) << "\n ==========================
<< endl;
cout << setw(22) << "Enter Selection > ";
cin >> choice;
return choice;
}
void GetData( voter voterlist[], int& error, ifstream& infile, int& size)
{
int age,
idnumber,
birthyear,
currentage = 0,
numvoters = 0;
char lastname[25],
firstname[25],
party[2],
trash[2];
OpenInput( infile, "Give name of Data File: " );
while (infile.good() )
{
cout.setf(ios::left);
infile >> idnumber;
cout.setf(ios::left);
infile.getline(trash,2);
infile.getline(lastname,25
cout.setf(ios::left);
infile.getline(firstname, 25, '\t');
cout.setf(ios::left);
infile.getline(party, 2, '\t');
// party = toupper(party);
cout.setf(ios::left);
infile >> birthyear;
cout.setf(ios::left);
age = 2003 - birthyear;
if ((strcmp(party, "r") == 0) || (strcmp(party, "R") == 0) ||
( strcmp(party, "d") == 0) || (strcmp(party, "D") == 0) ||
( strcmp(party, "l") == 0) || (strcmp(party, "L") == 0) ||
( strcmp(party, "c") == 0) || (strcmp(party, "C") == 0))
{
if ((idnumber > 1000) && ( idnumber < 10000))
{
if ((age > 17) && (age < 126))
{
voterlist[numvoters] = voter(idnumber,lastname, firstname, party, birthyear, currentage);
++ numvoters;
}
else
error = error + 1;
}
else
error = error + 1;
}
else
error = error + 1;
if (infile.fail())
break;
size = numvoters;
}
infile.close();
}
void AddVoter(voter voterlist[], int& size)
{
cls();
size++;
voterlist[size-1].Add();
}
void EditVoter(voter voterlist[], int size)
{
int choice;
PrintReport(voterlist, size);
cout<<"Which voter do you wish to edit: ";
cin>>choice;
choice--;
voterlist[choice].Edit();
}
void PrintReport(voter voterlist[], int size)
{
cls();
int label = 1;
cout << "Report for: Data.txt"
<< endl
<< endl;
cout << "Label" << setw(10)
<< "Voter Id" << setw(11)
<< "Last Name" << setw(12)
<< "First Name" << setw(7)
<< "Party" << setw(11)
<< "Birthyear" << setw(5)
<< "Age"
<< endl;
cout << "=====" << setw(10)
<< "========" << setw(11)
<< "=========" << setw(12)
<< "==========" << setw(7)
<< "=====" << setw(11)
<< "=========" << setw(5)
<< "==="
<< endl;
for (int n = 0;n < size ;n++)
{
voterlist[n].print(label);
label++;
}
cout << endl;
}
void SaveFile(voter voterlist[], ofstream& outfile, int size)
{
cls();
OpenOutput(outfile);
for (int n = 0;n < size ;n++)
{
voterlist[n].disksave(outf
}
outfile.close();
}
void SaveReport(voter voterlist[], ofstream& outfile, int size)
{
cls();
OpenOutput(outfile);
outfile << "Report for: Data.txt"
<< endl
<< endl;
outfile << "Id Number" << setw(11)
<< "Last Name" << setw(15)
<< "First Name" << setw(12)
<< "Party Id" << setw(12)
<< "Bith Year" << setw(13)
<< "Current Age" << endl;
outfile << "=========" << setw(11)
<< "=========" << setw(15)
<< "==========" << setw(12)
<< "========" << setw(12)
<< "==========" << setw(13)
<< "===========" << endl;
for (int n = 0;n < size ;n++)
{
voterlist[n].disksave(outf
}
outfile.close();
}
void DeleteVoter(voter voterlist[], int& size)
{
int choice;
PrintReport(voterlist, size);
cout<<"Which voter do you wish to delete: ";
cin>>choice;
for (int i=choice - 1; i< size - 1; i++) {
voterlist[i] = voterlist[i+1];
}
size--;
return;
}
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: meow00Posted on 2003-12-09 at 15:37:36ID: 9908475
Comments are available to members only. Sign up or Log in to view these comments.