Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 138 139 [140] 141 142 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 906588 times)

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2085 on: March 29, 2012, 11:27:25 pm »

I'll tell you if the department's server ever comes back online...can't easily access my stuff right now.

How's your project coming?  Gonna keep it in Java or try to fix your C++ problem?
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2086 on: March 29, 2012, 11:32:08 pm »

If I can figure out what is causing the C++ problem, I'd like to use C++. But, for right now, I'm going to develop it further in Java.

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2087 on: March 29, 2012, 11:36:07 pm »

If Java starts annoying you a bit too badly, it's easy to shift it to Groovy or Scala or one of the other fifty languages that run on the JVM and are partly or largely compatible with Java.  Obviously, I can help with any Java problems you have.  I can probably help if you use one of the other things that run on the JVM as well.  Might be something worth looking into.
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2088 on: March 29, 2012, 11:38:47 pm »

Code: [Select]
name = new String(n); // This is bs. Are Strings primitives or objects? MAKE UP YOUR MIND, JAVA!

Oh, I wouldn't say it annoys me too badly...

Yes, that is actually an except from my Java code.

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2089 on: March 29, 2012, 11:40:45 pm »

I know you didn't miss my rant on Java Strings...you linked it in the OP.  Might be entertaining to read again, though.
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2090 on: March 29, 2012, 11:54:16 pm »

Yeah, I know all that isn't necessary. I did it for kicks, because I was pissed that C++ wasn't working for me and that I would have to use Java for the time being. Everything that's wrong with Java came rushing back to me.

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2091 on: March 30, 2012, 12:01:27 am »

If my rant doesn't show it enough, it pisses me off, too.  That's why I suggested using one of the other things running on the JVM.  These alternative languages that run on the JVM correct some of the things about Java that piss us off or are just plain bad.

I like Java, but even I'll admit it has issues.  You may or may not see improvement using something else.  I'd suggest Scala solely because you don't have to re-write your code.  You can change it as needed and leave the rest as Java.  Scala looks like an interpreted language.  Ruby- or Python-ish.  Groovy isn't 100% compatible with Java like Scala is, but also does a great job of simplifying the code and, by sacrificing full compatibility, adds some really very nice new features.  Do you want me to talk about either of them in more detail?  Or some other JVM-compatible language?
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2092 on: March 30, 2012, 12:16:24 am »

I'm interested in both.

EDIT: By both, I meant Scala and Groovy.
« Last Edit: March 30, 2012, 12:20:26 am by Mego »
Logged

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2093 on: March 30, 2012, 10:45:41 am »

All part of my evil plan to get you all to join the Cult of the JVM.  Worship the JVM.  GLORY TO THE JVM!!!

I'll try to get to writing something up tonight.  Hopefully I have time.  It depends how long it takes me to get frustrated with my CS homework.
Logged

armeggedonCounselor

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2094 on: March 30, 2012, 11:29:14 am »

Having trouble with a C++ assignment. Can you help?


and

Spoiler: The Program (click to show/hide)
Logged
Quote from: Stargrasper
It's an incredibly useful technique that will crash the computer if you aren't careful with it.
That really describes any programming.

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2095 on: March 30, 2012, 11:46:29 am »

Simple problem: The copy constructor for streams is protected, so you can't publicly access it. In your functions' arguments, change all of the streams to references. You did that for openFiles, but not for the other functions.

Code: [Select]
#include <fstream>
#include <iostream>
#include <iomanip>

using namespace std;

void openFiles(ifstream&, ofstream&);
void initialize();
void sumGrades(ifstream&, ofstream&, int&, int&, double&, double&);
void averageGrade(int, int, double, double, double&, double&);
void printResults(ifstream&, ofstream&, int, int, double, double, double, double);

int main()
{
cout << "See final.txt for results." << endl;

initialize();

system("pause");

return 0;
}

void initialize()
{
int countFemale = 0;
int countMale = 0;
double sumFemaleGPA = 0.0;
double sumMaleGPA = 0.0;
double averageMaleGPA = 0.0;
double averageFemaleGPA = 0.0;
ifstream inGrades;
ofstream outGrades;
openFiles(inGrades, outGrades);
sumGrades(inGrades, outGrades, countFemale, countMale, sumFemaleGPA, sumMaleGPA);
averageGrade(countFemale, countMale, sumFemaleGPA, sumMaleGPA, averageMaleGPA, averageFemaleGPA);
printResults(inGrades, outGrades, countFemale, countMale, sumFemaleGPA, sumMaleGPA, averageMaleGPA, averageFemaleGPA);
}
void openFiles(ifstream& inGrades, ofstream& outGrades)
{
inGrades.open("Ch7_Ex6Data.txt");
outGrades.open("final.txt");

outGrades << fixed << showpoint << setprecision(3);
}
void sumGrades(ifstream& inGrades, ofstream& outGrades, int& countFemale,
int& countMale, double& sumFemaleGPA, double& sumMaleGPA)
{
char gender;
double grade;

while (inGrades)
{
inGrades >> gender >> grade;
if (gender == 'm')
{
countMale++;
sumMaleGPA = sumMaleGPA + grade;
}
else
{
countFemale++;
sumFemaleGPA = sumFemaleGPA + grade;
}
}
}
void averageGrade(int countFemale, int countMale, double sumFemaleGPA, double sumMaleGPA,
double& averageMaleGPA, double& averageFemaleGPA)
{
averageMaleGPA = sumMaleGPA / countMale;
averageFemaleGPA = sumFemaleGPA / countFemale;
}
void printResults(ifstream& inGrades, ofstream& outGrades, int countFemale, int countMale,
double sumFemaleGPA, double sumMaleGPA, double averageMaleGPA, double averageFemaleGPA)
{
outGrades << "Processing Grades." << endl;
outGrades << inGrades;
outGrades << "Sum Female GPA:" << sumFemaleGPA << endl;
outGrades << "Sum Male GPA:" << sumMaleGPA << endl;
outGrades << "Male count:" << countMale << endl;
outGrades << "Female count:" << countFemale << endl;
outGrades << "Male Average:" << averageMaleGPA << endl;
outGrades << "Female Average:" << averageFemaleGPA << endl;
inGrades.close();
outGrades.close();
}

armeggedonCounselor

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2096 on: March 30, 2012, 11:56:07 am »

Ah. I see.

Well, I figured it would be something glaringly obvious.

EDIT: And now I have a logic error somewhere.
Spoiler: The Input Data (click to show/hide)

I should be getting a count of fourteen for each, and a sum of 46.99 for females and 46.67 for males.

Instead, I'm getting a count of 15 females and a sum of 50.97 for females.

The problem is almost certainly somewhere in here:

Code: (void sumGrades) [Select]
void sumGrades(ifstream& inGrades, ofstream& outGrades, int& countFemale,
int& countMale, double& sumFemaleGPA, double& sumMaleGPA)
{
char gender;
double grade;

while (inGrades)
{
inGrades >> gender >> grade;
if (gender == 'm')
{
countMale++;
sumMaleGPA = sumMaleGPA + grade;
}
else
{
countFemale++;
sumFemaleGPA = sumFemaleGPA + grade;
}
}
inGrades.close();
}

But I can't see it.
« Last Edit: March 30, 2012, 12:27:57 pm by armeggedonCounselor »
Logged
Quote from: Stargrasper
It's an incredibly useful technique that will crash the computer if you aren't careful with it.
That really describes any programming.

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2097 on: March 30, 2012, 12:36:21 pm »

As near as I can tell, your last input is being double counted.
Logged

armeggedonCounselor

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2098 on: March 30, 2012, 12:41:35 pm »

That's what I figured, but as far as I know there's no reason for that to happen. The extraction operator (look at me, I can use the fancy words) should remove it from the in file stream, and discard it once it's done. I suppose it could be because the inGrades still evaluates as true until inGrades fails to pull anything out to put it into....

I think I figured it out.

I did figure it out! VICTORY!

Take that, homework!
« Last Edit: March 30, 2012, 12:43:37 pm by armeggedonCounselor »
Logged
Quote from: Stargrasper
It's an incredibly useful technique that will crash the computer if you aren't careful with it.
That really describes any programming.

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2099 on: March 30, 2012, 01:14:42 pm »

Happens all the time.  Best possible way to solve a problem is to describe it to the person next to you.
Logged
Pages: 1 ... 138 139 [140] 141 142 ... 796