Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8947505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:46:40+00:00 2026-06-15T12:46:40+00:00

**No direct answers or code examples please, this is my homework which i need

  • 0

**No direct answers or code examples please, this is my homework which i need to learn from. I’m looking for help concerning the algorithm i need to develop.

I seem to be having a logic error in coming up with a solution for a portion of my class work, the program involves multiple files, but here is the only relevant portion:

I have a file PlayerStats that holds the stats for a basketball player in:

  • rebounds
  • points
  • assists
  • uniform #

my initial reaction would be to create a while loop and read these into a temporary struct that holds these values, then create a merge function that merges the values of the temp struct with the inital array of records, simple enough?

struct Baller
{
   //other information on baller
   int rebounds;
   int assists;
   int uniform;
   int points;
   void merge(Baller tmp); //merge the data with the array of records
}

//in my read function..
Baller tmp; 
int j = 0;
inFile << tmp.uniform << tmp.assists << tmp.points << tmp.rebounds
while(inFile){
    ArrayRecords[j].merge(tmp);
    j++;
    //read in from infile again
}

The catch:
The file can have an arbitrary number of spaces between the identifiers, and the information can be in any order(leaving out the uniform number, that is always first). e.g.

PlayerStats could be

11 p3 a12 r5 //uniform 11, 3 points 12 assists 5 rebounds
//other info

OR

   11 p    3 r  5  a      12 //same exact values

What I’ve come up with


can’t seem to think of an algorithm to grab these values from the file in the correct order, i was thinking of something along these lines:

inFile << tmp.uniform; //uniform is ALWAYS first
getline(inFile,str);  //get the remaining line
int i = 0;
while(str[i] == " ") //keep going until i find something that isnt space
    i++;

if(str[i] == 'p')  //heres where i get stuck, how do i find that number now?

else if(str[i] == 'a')

eles if(str[i] = 'r'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:46:41+00:00Added an answer on June 15, 2026 at 12:46 pm

    If you’re only going to check one letter, you could use a switch statement instead of if / else, that would make it easier to read.

    You know where the number starts at that point, (hint: str[i+1]), so depending on what type your str[] is, you can either use atoi if its a char array, or std::stringstream if it’s an std::string.

    I’m tempted to give you some code, but you said not too. If you do want some, let me know and I’ll edit the answer with some code.

    Instead of using a ‘merge’ function, try using an std::vector so you can just push_back your structure instead of doing any ‘merging’. Besides, your merge function is basically a copy assignment operator, which is created by the compiler by default (you don’t need to create a ‘merge’ function), you just need to use = to copy the data across. If you wanted to do something special in your ‘merge’ function, then you should overload the copy assignment operator instead of a ‘merge’ function. Simples.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am aware that this is not a direct 'development' question but I need
Please let me know how to bug fix this code . I tried and
There are not really and direct answers on this, so I thought i'd give
Consider the following code which is typcial of many ChannelFactory examples: WSHttpBinding myBinding =
OK, I have scoured this site as well as others looking for answers to
I was looking all over and couldn't get a direct and clear answer. Is
Is there a direct analog to this in C++? for num in [1,4,5] :
im trying to use direct store in Extjs heres the code to my store
This is a very direct follow-up on this question . Using matplotlib , I'd
Can someone please direct me on how I can add something similar to inputAccessoryView

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.