473,507 Members | 2,388 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

File stream

9 New Member
Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include<iomanip>
  3. #include<fstream>
  4. using namespace std;
  5.  
  6.  
  7.  
  8. struct info_struct
  9. {
  10.     char ID[5];
  11.     int number_year;
  12.     int number_CD;
  13. };
  14.  
  15.  
  16.  
  17. void Display(info_struct[], int);
  18. void Passing(info_struct[], int);
  19.  
  20. int main()
  21. {
  22.     char select;
  23.     cout << setprecision(2)
  24.         << setiosflags(ios::fixed)
  25.         << setiosflags(ios::showpoint);
  26.  
  27.  
  28.  
  29.     info_struct info[4] = 
  30.     {{"M123" , 2, 3},
  31.     {"M225", 1, 6},
  32.     {"M248", 2, 1},
  33.     {"M552", 3, 5}};
  34.     do
  35.     {
  36.  
  37.     cout << "Mr. Muzik's Fanatastic Music Club\n";
  38.     cout << "==================================\n";
  39.     cout << "A - Display Annual Report\n";
  40.     cout << "B - Input Information\n";
  41.     cout << "Please make a selection: ";
  42.     cin >> select;
  43.  
  44.     switch(select)
  45.     {
  46.     case 'A':
  47.     case 'a':
  48.  
  49.  
  50.              Display(info, 4);
  51.  
  52.         break;
  53.  
  54.             Passing(info, 4);
  55.  
  56.     case 'B':
  57.     case 'b':
  58.  
  59.  
  60.         break;
  61.     default:
  62.         cout << endl << endl
  63.             << "Invalid Property Code! Try again.\n" << endl;
  64.         break;
  65.  
  66.  
  67.     }
  68.     }while((select != 'a' || select != 'A') && (select != 'B' || select != 'b'));
  69.     return 0;
  70. }
  71.  
  72.  
  73. void Display(info_struct NEW[], int size)
  74. {
  75.             int i;
  76.             cout << endl << endl;
  77.         cout << setw(20)<< "ID" 
  78.              << setw(20) << "Number of Year"
  79.              << setw(20) << "Number of CD bought"  << endl;
  80.  
  81.             for (i = 0; i < size; ++i)
  82.             {
  83.                 cout << endl;
  84.                 cout << setw(20)<< NEW[i].ID 
  85.                      << setw(20)<< NEW[i].number_year 
  86.                      << setw(20)<< NEW[i].number_CD  << endl;
  87.             }
  88. }
  89. void Passing(info_struct NEW_2, int size_2)
  90.  
  91. {
  92.     int row;
  93.  
  94.     cout << endl;
  95.     cout << "Enter the table values: "
  96.         <<endl << endl;
  97.     for(row = 0; row < size_2; ++row)
  98.     {
  99.         cout << endl;
  100.  
  101.         cout << "ID Number: ";
  102.         cin.getline(NEW_2[row].ID, 5);
  103.  
  104.         cout << "Number of Year: ";
  105.         cin >> NEW_2[row].number_year;
  106.  
  107.         cout << "Number of CD bought: ";
  108.         cin >> NEW_2[row].number_CD;
  109.  
  110.         cin.get();
  111.     }
  112. }

I am a bit confused on why it doesnt work I am trying to have it enter the information, from the void. I guess I want to make the stucture interactive inside or outside the main?
Apr 28 '08 #1
4 1372
Savage
1,764 Recognized Expert Top Contributor
What errors are you getting?

Also take a good look at this:

Expand|Select|Wrap|Line Numbers
  1. case 'A':
  2. case 'a':
  3.  
  4.  Display(info, 4);
  5.  break;
  6.  
  7. Passing(info, 4);
  8.  
  9. case 'B':
  10. case 'b':

And please use code tags around your code.(Select your code and press # button,you can also specify a language e.g[code=C] will use C markings)

Savage
Apr 28 '08 #2
Learner21
9 New Member
Thanks a whole bunch I was just curious:
On my passing structure whenever the user types in more then 2 values the whole program loops:
Expand|Select|Wrap|Line Numbers
  1. void Passing(info_struct NEW_2[], int size_2)
  2.  
  3. {
  4.     int row; 
  5.     cout << endl;
  6.     cout << "Enter the table values: "
  7.         << endl << endl;
  8.     for(row = 0; row < size_2; ++row)
  9.     {
  10.         cout << endl;
  11.  
  12.         cout << "ID Number: ";
  13.         cin.getline(NEW_2[row].ID, 4);
  14.  
  15.         cout << "Number of Year: ";
  16.         cin >> NEW_2[row].number_year;
  17.  
  18.         cout << "Number of CD bought: ";
  19.         cin >> NEW_2[row].number_CD;
  20.  
  21.         cin.get();
  22.     }
  23. }
  24.  
I hope I placed in the code tags right. I thought if I had that number 4 it wouldnt matter. I try adding a do while but it ended looping the number of year and CD I am still working on it I just wish I knew what I should do.
Apr 28 '08 #3
Savage
1,764 Recognized Expert Top Contributor
I believe that solution to your problem lies in this thread
Apr 28 '08 #4
Learner21
9 New Member
I believe that solution to your problem lies in this thread
Thank you for your help and patience
Apr 29 '08 #5

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

Similar topics

6
1762
by: Siddharth Taneja | last post by:
Hi, I have a very simple prg over here, trying to read the lines of a file #include <iostream> #include <fstream> #include <iostream> #include <string> using namespace std;
2
13076
by: gnv | last post by:
Hi all, I am writing a cross-browser(i.e. 6 and netscape 7.1) javascript program to save an XML file to local file system. I have an xml string like below: var xmlStr = "<?xml version="1.0"...
19
3203
by: Johnny Google | last post by:
Here is an example of the type of data from a file I will have: Apple,4322,3435,4653,6543,4652 Banana,6934,5423,6753,6531 Carrot,3454,4534,3434,1111,9120,5453 Cheese,4411,5522,6622,6641 The...
13
4281
by: Sky Sigal | last post by:
I have created an IHttpHandler that waits for uploads as attachments for a webmail interface, and saves it to a directory that is defined in config.xml. My question is the following: assuming...
5
3034
by: Daniel Corbett | last post by:
I am trying to save a file dynamically created in a webpage. I get the following headers, but cannot figure out how to save the attachment. I am basically trying to replicate what internet...
5
3155
by: IcingDeath via DotNetMonster.com | last post by:
I am building this SQL Server database app in which i can store files. In order to display files I want to have the app show the associated icon for the extension of the file that is in the...
4
2489
by: rony_16 | last post by:
Hi, I have a program that connects to a site With WebRequest and WebResponse . The response of this site is a file (csv file). The problem is that the file do not comes as a stream , hi is a part...
5
64582
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C++ programming. FYI Although I have called...
6
17103
by: J055 | last post by:
Hi I have the following code. I upload an XML file using the FileUpload object, store the stream in a session so the user gets the chance to confirm some options then pass the stream from the...
45
4373
by: Dennis | last post by:
Hi, I have a text file that contents a list of email addresses like this: "foo@yahoo.com" "tom@hotmail.com" "jerry@gmail.com" "tommy@apple.com" I like to
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7319
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
7376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7485
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5042
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1542
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.