printing stock structure

hi all
I have written a block of code that answers the following:

Write a C function that reads from the user (keyboard) the information about the transistors in stock, and stores this information in the Stock structure.

input info was: different transistor, manufacturer’s ID, polarity, maximum power, current gain, number in stock

Now I have to print all the input data in tabular form. How do I do that? If I use printf(%s%s...) and then list the input data in the printf statement, it will only print the headings wont it? How do I print all the input data with correct data under each correct heading?

Thanks in advance
You'd need to create a struct or a class named Stock that has the input date stored in member variables.

Then write a Print() function for it that will display the data as you want it.
Last edited on
How exactly do I go about creating a struct or class that can store that data? I can provide the code if it will make things easier
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
struct STOCK // Make a struct
{
    int info1; // This is data in the struct.
    int info2;
};

std::ifstream& operator >> (std::ifstream& in, STOCK& s)
{
    return (in >> s.info1 >> s.info2); // cin>>MyStock will now read into info1 and info2
}

std::ofstream& operator << (std::ofstream& out, STOCK& s)
{
    return (out << s.info1 << ' ' << s.info2); // cout<<MyStock will now print "info1 info2".
}
Topic archived. No new replies allowed.