Quantcast

Maximum PC

It is currently Thu Nov 27, 2014 6:00 pm

All times are UTC - 8 hours




Post new topic Reply to topic  [ 48 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: Not quite finished
PostPosted: Mon Sep 28, 2009 4:01 pm 
Sharptooth
Sharptooth
User avatar

Joined: Fri Apr 24, 2009 7:13 pm
Posts: 499
Hey, so i'm writing a program that calculates the slugging percentage. I'm just learning the function thing in C++ so any help is appreciated. I think i have some major error in hear, but i'm not sure how to fix them. I'd like to keep the current format/shell/layout so please don't reccomend any changes. Thanks in advance!


Code:
#include <iostream>

#include <iomanip>


using namespace std;


string getName();

void getStats (int &AB, int &H, int &BB, int &HBP, int &SF, int &TB);

double calculate (int AB, int H, int BB, int HBP, int SF, int TB);

void display (double OPS, string name);


int main()

{

double OPS;

int AB, H, BB, HBP, SF, TB;

string name;

name = getName ();

getStats (AB, H, BB, HBP, SF, TB);

OPS = calculate (AB, H, BB, HBP, SF, TB);

display (OPS, name);

return 0;

}


void getStats (int &AB, int &H, int &BB, int &HBP, int &SF, int &TB)

{

string name;

cout <<"Enter the player's name: ";

cin >> name;

cout << endl;

cout <<"Enter the player's total at bats; ";

cin >> AB;

cout <<"Enter the player's number of hits: ";

cin >> H;

cout <<"Enter the player's number of walks: ";

cin >> BB;

cout <<"Enter the player's number of times hit by a pitch: ";

cin >> HBP;

cout <<"Enter the player's number of sacrifice flies: ";

cin >> SF;

cout <<"Enter the player's total number of bases: ";

cin >> TB;

}



double calculate (int AB, int H, int BB, int HBP, int SF, int TB)

{

return (AB*(H+BB+HBP)+TB*(AB+BB+SF+HBP))/(AB*(AB+BB+SF+HBP));

}


void display (OPS, name)


{

cout << name << " OPS is: " << OPS;

return 0;

}




Last edited by zippzom on Sun Nov 22, 2009 7:06 pm, edited 1 time in total.

Top
  Profile  
 
 Post subject:
PostPosted: Mon Sep 28, 2009 4:08 pm 
Java Junkie
Java Junkie
User avatar

Joined: Mon Jun 14, 2004 10:23 am
Posts: 24236
Location: Granite Heaven
What class is this for?


Top
  Profile  
 
 Post subject:
PostPosted: Mon Sep 28, 2009 4:15 pm 
Sharptooth
Sharptooth
User avatar

Joined: Fri Apr 24, 2009 7:13 pm
Posts: 499
introduction to programming 1


Top
  Profile  
 
 Post subject:
PostPosted: Mon Sep 28, 2009 5:01 pm 
Java Junkie
Java Junkie
User avatar

Joined: Mon Jun 14, 2004 10:23 am
Posts: 24236
Location: Granite Heaven
I thought so.

We don't do homework support here. We do help .. but you have to be more specific than 'this doesn't work'.

Here are some guidelines:

* We are not going to copy / paste your code into our compilers and trouble-shoot. If it doesn't work, give us a DETAILED description of what is going wrong .. including compiler errors. We'll guess and explain why we think something may be amiss, but we won't debug your work .. that is your job.

* We are happy to provide supplemental advice on top of your prof's teaching. If you don't understand a concept, we'll happily expand on it. Good: I don't really understand how encapsulation supports OOP.

* We will help you tune a program if you tell us what you think is wrong or what you are looking for .. but we will never actually provide the code. We might tell you to replace one data structure with another, for instance, but we will not actually provide you with the code.


So .. what is your program NOT doing? :)


Top
  Profile  
 
 Post subject:
PostPosted: Mon Sep 28, 2009 5:08 pm 
Sharptooth
Sharptooth
User avatar

Joined: Fri Apr 24, 2009 7:13 pm
Posts: 499
Ok, sorry. :oops:

Just to clarify, this isn't homework, but in class work that i can get help with, but i hate waiting 3 days to get support. Second of all, i can't actually check right now because the only mac in my house (i use xcode) is being used. I do remember that there were no errors visible in the code, but when i clicked on like "error location," it came up with some reference error or something. I'll put up specifics tomorrow.

Sorry for my presumptuous attitude


Top
  Profile  
 
 Post subject:
PostPosted: Mon Sep 28, 2009 5:15 pm 
Java Junkie
Java Junkie
User avatar

Joined: Mon Jun 14, 2004 10:23 am
Posts: 24236
Location: Granite Heaven
No need to apologise ... I need to put the rules into a sticky or something.

I'll take a closer look at your code when I get a chance .. and I'm sure others will as well. :)


Top
  Profile  
 
 Post subject:
PostPosted: Tue Sep 29, 2009 4:30 am 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
Okay, I am a nice guy and I had a few minutes to drop it into a compiler. Now, the only thing is I am in Windows XP, and working under Visual Studio 2008:

I get 4 errors:
Quote:
Error 1 error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) c:\visual studio 2008\projects\testapp\testapp\testapp.cpp 49 TestApp


Error on middle line:
Code:
cout <<"Enter the player's name: ";
cin >> name;
cout << endl;


These next three errors, all go with the last block of code:
Quote:
Error 2 error C2065: 'OPS' : undeclared identifier c:\visual studio 2008\projects\testapp\testapp\testapp.cpp 90 TestApp

Quote:
Error 3 error C2065: 'name' : undeclared identifier c:\visual studio 2008\projects\testapp\testapp\testapp.cpp 90 TestApp

Quote:
Error 4 error C2448: 'display' : function-style initializer appears to be a function definition c:\visual studio 2008\projects\testapp\testapp\testapp.cpp 93 TestApp


Code:
void display (OPS, name)
{
   cout << name << " OPS is: " << OPS;
   return 0;
}


Here are my hints:
  • You are missing an #include.
  • Your function definition is incorrect.
  • You also have some mis-matched types in your program.
  • I fixed it by typing 31 characters and deleting one line.


Top
  Profile  
 
 Post subject:
PostPosted: Tue Sep 29, 2009 4:38 am 
Sharptooth
Sharptooth
User avatar

Joined: Fri Apr 24, 2009 7:13 pm
Posts: 499
Ya, i fixed it in class, but thanks for all the help. I just had some careless mistakes that Crashtech helped me find.


Top
  Profile  
 
 Post subject:
PostPosted: Tue Sep 29, 2009 4:43 am 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
Don't feel too bad... I recently spent over an hour fighting with an application I am working on in C++ because I left out a single ;

:oops:

I program for a living... but C++ is NOT the language I use every day. I haven't even touched it in a couple years now and I just forget all those differences between it and C#. I have probably written 20 to 30 times as many lines of C# as I have C++.


Top
  Profile  
 
 Post subject:
PostPosted: Wed Nov 11, 2009 12:40 am 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
CrashTECH wrote:
Don't feel too bad... I recently spent over an hour fighting with an application I am working on in C++ because I left out a single ;

:oops:

I program for a living... but C++ is NOT the language I use every day. I haven't even touched it in a couple years now and I just forget all those differences between it and C#. I have probably written 20 to 30 times as many lines of C# as I have C++.

/me points finger... =)


Top
  Profile  
 
 Post subject:
PostPosted: Wed Nov 11, 2009 1:07 am 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
OK, I was a little bored and decided to code this up in LISP. One of the first things that caught my eye was the fugly equation in calculate.

I would highly recommend reducing all your equations before implementing them unless you have a really good reason not to do so.

Code:
(defun calc (ab h bb hbp sf tb)
           (+
            (/ (+ h bb hbp) (+ ab bb sf hbp))
            (/ tb ab 1.0)))


Note: the 1.0 at the end of the last line of code causes the LISP interpreter to return a floating point value instead of a ratio (ie .5 vs 1/2).


Top
  Profile  
 
 Post subject:
PostPosted: Wed Nov 11, 2009 5:29 am 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
Gadget wrote:
OK, I was a little bored and decided to code this up in LISP.
Masochist.


Top
  Profile  
 
 Post subject:
PostPosted: Wed Nov 11, 2009 10:31 pm 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
CrashTECH wrote:
Gadget wrote:
OK, I was a little bored and decided to code this up in LISP.
Masochist.


LOL... coming from someone who spent an hour hunting down a semi-colon?! Actually, LISP is still the most commonly used language for prototyping -- that's because it rocks. ;)


Top
  Profile  
 
 Post subject:
PostPosted: Fri Nov 13, 2009 2:56 pm 
Coppermine
Coppermine
User avatar

Joined: Mon Feb 21, 2005 9:33 am
Posts: 692
Location: Grass Valley, CA
Gadget wrote:
CrashTECH wrote:
Gadget wrote:
OK, I was a little bored and decided to code this up in LISP.
Masochist.


LOL... coming from someone who spent an hour hunting down a semi-colon?!


Ha! Don't laugh it will happen to you as well! :P

Gadget wrote:
Actually, LISP is still the most commonly used language for prototyping -- that's because it rocks. ;)


Yes, the LISP porgramming language is unmatched in its ability to transform the difficult-to-understand into the completely unfathomable. :twisted:

/me runs for cover...


Top
  Profile  
 
 Post subject:
PostPosted: Fri Nov 20, 2009 1:58 am 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
SpazzAttack wrote:
Gadget wrote:
CrashTECH wrote:
Gadget wrote:
OK, I was a little bored and decided to code this up in LISP.
Masochist.


LOL... coming from someone who spent an hour hunting down a semi-colon?!


Ha! Don't laugh it will happen to you as well! :P

LOL... Oh, I gave up chasing down semi-colons a long time ago. My philosophy goes something like "unless you're writing system software, why the hell are you using C?". I've never had a problem keeping Java straight, probably due to the compiler writers over at Sun more than anything else.

SpazzAttack wrote:
Gadget wrote:
Actually, LISP is still the most commonly used language for prototyping -- that's because it rocks. ;)


Yes, the LISP porgramming language is unmatched in its ability to transform the difficult-to-understand into the completely unfathomable. :twisted:

/me runs for cover...

If it wasn't so late, I might bother... ;-)


Top
  Profile  
 
 Post subject:
PostPosted: Fri Nov 20, 2009 2:16 am 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
SpazzAttack wrote:
Gadget wrote:
Actually, LISP is still the most commonly used language for prototyping -- that's because it rocks. ;)

Yes, the LISP porgramming language is unmatched in its ability to transform the difficult-to-understand into the completely unfathomable. :twisted:

/me runs for cover...

As there aren't any new interesting topics, I'll go ahead and bother. =)

The other day I decided to write a couple small scripts to help me add id3 tag info to a bunch of old mp3 files that I ripped back in the Napster days using BladeEnc on Linux. There were something like 500 files, and I didn't want to have to shuffle songs around in a program like Tag&Rename or MP3Tag (and I felt like doing some programming), so I decided to write a script to append the track number to the front of the file. Then when I opened the file up in either program, they'd largely be in the correct order and I would just swap one or two songs around and be done with it.

I was going to write a short script to download the song info from one of the song databases, but a friend called during this part of the project, so I ended up doing this part by hand while talking to her on the phone. I created a text file with the raw song info and would read it into an association list (aka a-list or "poor man's hash table"). Basically, it is a list of lists where the first element in each sub-list is the key. It looked something like...

'(("song 1" 3) ("song 2" 9) ...) ;;where 3 is the track # for song 1

Of course, it had approximately as many entries as there were songs/files that needed track info. I figured there were probably going to be any collisions. Anyways, as you can imagine, quite a few of them didn't match up due to spelling/naming issues and what not.

I needed to sort the list based on the song names...
This is the part where you show us an easy way to do it in C++.

I also wanted to make sure that there were any name collisions.
Again, you're turn.

This should be interesting... ;-)


Top
  Profile  
 
 Post subject:
PostPosted: Fri Nov 20, 2009 4:54 am 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
Gadget wrote:
CrashTECH wrote:
Gadget wrote:
OK, I was a little bored and decided to code this up in LISP.
Masochist.


LOL... coming from someone who spent an hour hunting down a semi-colon?! Actually, LISP is still the most commonly used language for prototyping -- that's because it rocks. ;)
I didn't hunt for the semi because I WANTED to... lol

Anybody who chooses to program in LISP wants to hurt themselves :)


Top
  Profile  
 
 Post subject:
PostPosted: Fri Nov 20, 2009 4:56 am 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
You want a hash table where the song name is the key and the track is the elements?


Top
  Profile  
 
 Post subject:
PostPosted: Fri Nov 20, 2009 7:06 am 
Coppermine
Coppermine
User avatar

Joined: Mon Feb 21, 2005 9:33 am
Posts: 692
Location: Grass Valley, CA
[EDIT: I deleted the contents of this comment because I got a little too mean with it - Spazz]


Last edited by SpazzAttack on Fri Nov 20, 2009 11:22 am, edited 1 time in total.

Top
  Profile  
 
 Post subject:
PostPosted: Fri Nov 20, 2009 9:21 am 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
Oh snap!


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 48 posts ]  Go to page 1, 2, 3  Next

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

© 2014 Future US, Inc. All rights reserved.