CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2008
    Posts
    29

    Help i need some tips

    Ok, so my entire grade in my C++ class depends on whether i can pass this basic skills test or not, and i'm hoping you guys can give me some helpful pointers and tips to pass this. Here is all the info
    Code:
    The skills test will be offered in lab (and possibly in some evening 
    sessions in the final week of the course.) You can take it as many 
    times as needed, but not more than once on the same day. You will 
    have 50 minutes to write a working program that solves an 
    assigned problem in which you read information from a file, 
    
    containing character strings and numbers, store the information in 
    an array, and perform one of the following operations: 
     
    *print the average value of entries in the data set 
    *prompt the user for a descriptor and print the corresponding 
    value, or print ìinvalid descriptorî 
    *print the max value of entries in the data set 
    *print the min value of entries in the data set 
    *prompt the user for a descriptor and delete the corresponding 
    descriptor and value, or print ìinvalid descriptorî, and print the remaining entries in the data set 
    *prompt the user for a descriptor and value, add these to the data 
    set, and print the entries, including the new one 
     
    You will be told which of these things you have to do. 
     
    The file will contain a number of records, where each record 
    consists of a descriptor and an associated value, such as: 
     
    candidate name, vote (eg Nixon 200) 
    state, sales volume (eg Colorado 150) 
    month, average temperature (eg January 43.5) 
    part number, quantity (eg A34B2 250) 
    city, population (eg Denver 100200) 
    name, grade (eg Smith 93) 
    tooth, length (eg canine 34.2) 
     
    Your program must be able to read and store as many records as 
    there are in the file, up to some stated limit, without assuming how 
    many records are in the file. 
     
    Your program must define an use at least one appropriate struct 
    type, and at least one function other than main.
    Any tips are greatly appreciated. I specifically need help on being able to read in the data files, which will contain like a name, then the value there. What functions should i use to read in this data and store it into an array?
    Last edited by hrstar24; March 31st, 2008 at 12:21 PM.

  2. #2
    Join Date
    May 2007
    Posts
    811

    Re: Help i need some tips

    What exactly do you need here? Code snippets for each problem, entire program?

    We would gladly help you, but you need to show us your effort first.

  3. #3
    Join Date
    Aug 2005
    Location
    LI, NY
    Posts
    576

    Re: Help i need some tips

    Use ifstream to read data from a file.
    - Alon

  4. #4
    Join Date
    Jan 2004
    Location
    Düsseldorf, Germany
    Posts
    2,401

    Re: Help i need some tips

    Quote Originally Posted by hrstar24
    I specifically need help on being able to read in the data files, which will contain like a name, then the value there. What functions should i use to read in this data and store it into an array?
    To read in you use operator>>. Some code snipplet:
    Code:
    std::ifstream f("filename.txt");
    std::string s;
    float n;
    while (f >> s >> n) {
      // form a struct out of s and n and store it in the array
    }
    More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity. --W.A.Wulf

    Premature optimization is the root of all evil --Donald E. Knuth


    Please read Information on posting before posting, especially the info on using [code] tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured