Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
C++ help
#18
First, convert your main() into a function like update_gpa(float gpa, int* gender_count, float* total_gpa). Basically, all this function does is updating the scores. Once you did that, recode your main() to call this function.

Once that's done, you will need to use a file stream reader (which I totally forgot the syntax for) and I think there's a function readline to read in a line in the file. As you can see, line[0] is the gender, and the rest is a float. Substring will do the trick here.

Your main() will be something like this:
for each line in the file, gender = line[0], gpa = convert to float(line[1..n])
if gender is m, pass in the gpa, the male total, the male gpa total into update_gpa
otherwise, pass in the gpa, the female total, the female total gpa into update_gpa

IMO, that's clean modular programming.

To make this OOP, firstly, you need a class calls GpaManager, which has 4 vars, male_total, female_total, male_total_gpa, female_total_gpa and perhaps 2 constants, MALE and FEMALE.

Then, you would need a public function calls update_gpa(char gender, &float gpa) and

protected function update_female_gpa(&float gpa)
protected function update_male_gpa(&float gpa)

Note that you're only going to read the GPA, so it's OK to pass the reference.

In update_gpa, it does the if statement and calls the male/female version of the function.

you can also do a toString() function for the class GpaManager, so that you can do something like cout << GpaManager.

That's pretty much does all the GPA logics.

Now, you can do something like a StdinGpaManager, which reads the data in from the std input and/or a FileGpaManager, which reads the data in from the file.
Reply


Messages In This Thread
C++ help - by DrRusty - 2010-09-21, 10:03 AM
C++ help - by iamflip - 2010-09-21, 10:22 AM
C++ help - by DrRusty - 2010-09-21, 10:41 AM
C++ help - by Eos - 2010-09-21, 11:53 AM
C++ help - by Fiel - 2010-09-21, 12:23 PM
C++ help - by Eos - 2010-09-21, 12:34 PM
C++ help - by DrRusty - 2010-09-21, 12:42 PM
C++ help - by Eos - 2010-09-21, 12:47 PM
C++ help - by DrRusty - 2010-09-21, 12:55 PM
C++ help - by Fiel - 2010-09-21, 12:59 PM
C++ help - by Fiel - 2010-09-21, 01:21 PM
C++ help - by Stereo - 2010-09-21, 01:40 PM
C++ help - by DrRusty - 2010-09-21, 04:23 PM
C++ help - by Fiel - 2010-09-21, 04:35 PM
C++ help - by DrRusty - 2010-09-21, 05:02 PM
C++ help - by Fiel - 2010-09-21, 05:10 PM
C++ help - by DrRusty - 2010-09-21, 05:31 PM
C++ help - by GummyBear - 2010-09-22, 06:21 AM
C++ help - by DrRusty - 2010-09-22, 08:24 AM
C++ help - by GummyBear - 2010-09-22, 09:39 AM
C++ help - by Stereo - 2010-09-22, 01:41 PM
C++ help - by GummyBear - 2010-09-22, 07:15 PM
C++ help - by Fiel - 2010-09-22, 08:50 PM
C++ help - by GummyBear - 2010-09-23, 10:27 AM
C++ help - by DrRusty - 2010-09-27, 09:22 AM
C++ help - by Eos - 2010-09-27, 09:28 AM
C++ help - by DrRusty - 2010-09-27, 09:34 AM
C++ help - by Eos - 2010-09-27, 09:44 AM
C++ help - by Fiel - 2010-09-27, 10:13 AM
C++ help - by Eos - 2010-09-27, 10:27 AM
C++ help - by DrRusty - 2010-09-27, 10:28 AM
C++ help - by Eos - 2010-09-27, 10:34 AM
C++ help - by DrRusty - 2010-09-27, 11:28 AM
C++ help - by ArbalistMaster - 2010-09-27, 01:24 PM
C++ help - by Fiel - 2010-09-27, 03:44 PM
C++ help - by Stereo - 2010-09-27, 04:57 PM
C++ help - by GummyBear - 2010-09-28, 08:57 AM
C++ help - by Russt - 2010-09-28, 07:31 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)