By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,194 Members | 817 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,194 IT Pros & Developers. It's quick & easy.

Vectors/Stack programs

P: 1
Hello people, i am Chris from Jamaica W.I. and i have been having a problem with write vector and stack programs (but mostly vectors). Anyway, the program i am writing involves the whole pushing and popping theory. I have that in check. My problem is that i dont kno how to set the width and set precision between the fields such as ID No#, Date, Sold ..etc.. and output the information below each field in format that is displayed below. If someone could be so kind as the help me out. That would be great. At least illustrate how i would go at it in vector and stack.


Write the vector/stack program. For the following data:

The program should output looking like this---->

ID No# Date Sold Returned Brought
------ ------ -------- ------------- -----------
285 1/10/05 125 34 50
341 2/10/05 300 52 0
467 3/12/05 50 70 200
589 1/11/05 75 10 55


P.S. This what i have done so far but apparently it is crap.

int main()
{
int IDnum[4] = {285, 341, 467, 589};
vector <int> v1(IDnum,IDnum +15);
vector <int> :: iterator iter = v1.begin();

int Date;
int Sold;
int Returned;
int Brought;

cout << left << setw( 10 ) << "ID No#" << setw( 10 )
<< "Date"<< setw(10) << "Sold" << setw( 10 ) << "Returned"<< setw(10) << "Brought" << endl << fixed << showpoint;

void outputLine( int ID, int Date, int Sold, int Returned, int Brought );

{
cout << left << setw( 10 ) << IDnum << setw( 13 ) << Date
<< setw( 7 ) << setprecision( 2 ) << right << Sold<< setw(10) << Returned << setw(10) << Brought
<< endl;

} // end function outputLine
system("pause");
return 0;
}
Mar 22 '07 #1
Share this Question
Share on Google+
2 Replies


Roonie
P: 99
you need to set the precision?

if youre looking just to get everything lined up, try using tabs instead of the <iomanip> stuff . . . it might be easier.
Mar 22 '07 #2

Roonie
P: 99
(and is that all of your program? it looks like you are missing a few basics if you want it to generate that output . . . such as actually calling outputLine())
Mar 22 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.