Vectors/Stack programs

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ChriS99
    New Member
    • Mar 2007
    • 1

    #1

    Vectors/Stack programs

    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;
    }
    Last edited by ChriS99; Mar 22 '07, 06:23 PM. Reason: The title and instructions werent too clear
  • Roonie
    New Member
    • Mar 2007
    • 99

    #2
    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.

    Comment

    • Roonie
      New Member
      • Mar 2007
      • 99

      #3
      (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())

      Comment

      Working...