473,398 Members | 2,212 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

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;
}
Mar 22 '07 #1
2 1277
Roonie
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
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

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

Similar topics

12
by: Dave Theese | last post by:
Hello all, I'm in a poition of trying to justify use of the STL from a performance perspective. As a starting point, can anyone cite any benchmarks comparing vectors to plain old...
12
by: Fred Ma | last post by:
Hello, I was looking at Meyers's "Effective STL", item 23 about choosing between vectors and maps (at least that the choice for me). In many cases, using sorted vectors is faster for lookups. ...
2
by: mosfets | last post by:
Hi, I'm having a little trouble figuring out the difference in terms of memory allocation between: class person_info; class A { private:
5
by: lugal | last post by:
This might be more appropriate here. I'm new to C++, coming from a background in another languages that allowed a similar solution to work (Python). I wrote the following code in C++ based on the...
11
by: jagguy | last post by:
Could someone please tell me a use for vectors in C++. I know they are popular today but I am struggling to come up for a use. Since we now have database programs to connect to in the code, why...
24
by: John | last post by:
I know this is a very fundamental question. I am still quite confused if the program call stack stack should always grows upwards from the bottom, or the opposite, or doesn't matter?? That means...
10
by: pra1983 | last post by:
Can any one tell me how to use vectors insteard of two dimensional arrays... I was trying to store some thousands of values in an aray but i gives me error in between saying that " Stack is out...
87
by: CJ | last post by:
Hello: We know that C programs are often vulnerable to buffer overflows which overwrite the stack. But my question is: Why does C insist on storing local variables on the stack in the first...
62
by: jt | last post by:
hello everyone.. int fun() { /* anything */ } int main(void) { fun(); }
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.