Jump to content
Sign in to follow this  
TruflShufl

Anyone here dilly daddle in C++ programming?

Recommended Posts

I'm pretty sure someone here can help me, I remember several guys in a thread claiming they had careers in IT/Computer science so hopefully someone can help a brotha out  8-)

I'm in my first semester of C++ programming and only have a little programming experience from before (a semester in VB6, and some very simple tooling around with C). I got a crazy idea the other day to make a program that would calculate your score for the State vs. State competition we're having. It's a pretty simple calculation so a program doing this is kinda unnecessary but I thought it'd be a fun project and give me something to do at night this week while the weather is crappy.

Basically it prompts the user for a weight, then sets that weight to a object. Then it prompts the user for a state, then sets the state to that object. Now here is where it's getting hairy. I was going to put a switch statement in the getState function. The switch would basically take the state we've set and then set the record from that state into a private variable in the object (for use in processing at a later point). The problem I've run in to is that it refuses to use a string variable in a switch statement. Is there a way to make a string variable work in a switch statement? Option B would be to use an enumerated data type, but that would be harder to implement case insensitivity (i.e. if the user is trying to input Alabama, they may put in AL, al, Al, or aL; you know where I'm getting at).

So. any ideas?   :) If you want, I can provide the source files, just ask!

Share this post


Link to post
Share on other sites

Its been a lot of years since I have written any C code, but, here goes..

I thought that switch evaluates any expression and the expression can be integral or string, so in theory it should work. Are you using any type of quotes or single ticks? Is the variable you are using declared globally (if passing to the function)? You could try parsing the variable to a definition within the function. This would ensure that the var is assigned within the function and you are not missing an assignment somewhere.

Like I said, been a while. Haven't written any C code in over 8 or 9 years - was operating system drivers and system resource apps/utilities in UNIX/AIX (similar to windows dll's) for integration of applications (AIX src) within the OS.

One other thought though, putting on my IT architect hat here for a minute..

Although not as sexy as custom code, but MS access or excel should be able to provide the same (if not better) functionality. Ultimately what you are looking for is data collection and management two things that access and excel do reasonably well for single source. I know, not as much fun as coding, but think you might get a little more functionality out of it can focus on the function, interface and reporting instead of all the coding. Can use lists for the states and just input weights, dates and times and output to some custom reports.

Just a thought.

Good luck and let us know how it goes.

Eddie

Share this post


Link to post
Share on other sites

I haven't done much programming but I am in the IT profession and I haven't done any C++ programming but I have done some of this in java and I think it would be easier in javascript and it could be published on the site as a java applet. Just my thoughts. I have also done some PL/SQL programming, but I was never very good at starting code but I was reasonably proficient at modifying it and creating new code for existing code.

Share this post


Link to post
Share on other sites
I haven't done much programming but I am in the IT profession and I haven't done any C++ programming but I have done some of this in java and I think it would be easier in javascript and it could be published on the site as a java applet. Just my thoughts. I have also done some PL/SQL programming, but I was never very good at starting code but I was reasonably proficient at modifying it and creating new code for existing code.

+1.  I'm not an expert at either, I have a year experience in both, but wouldn't it be easier in Java, like stated above, you could probably figure a way to put it on BR.

Share this post


Link to post
Share on other sites

I appreciate the suggestions on alternative development ideas but I really wanna do this in C++. To be honest I have no intention of releasing (or even using it myself), it just seemed like a feasible idea I could apply towards my programming lessons. I just wanted to give myself a challenge I spose. I get bored here at college  ;D

I double checked my C++ book and it said for some reason the switch function can only be used with an integer or char variable. I think I might just go with a big if/else if statement.

I'm pretty much with you CFFF. During the last lab our professor actually passed out the object/header files and we just had to complete them then integrate them into our main.cpp file. I found it alot more frustrating to start from scratch this time around. I had to ask myself over and over last night "So...what am I going to do next?"  ;D That's ok, I have no intention of doing much programming after I graduate, I'd much rather go into system administration or security.

Thanks guys!  8-)

Share this post


Link to post
Share on other sites

You cannot use a String data type in a switch statement. So your right there.

There are what is called enumerators. Not sure exactly what your try to do.

If your trying to get a string for the state name and then putting that into your class then use an enumerator.

Are you trying to find the correct object to put some data in then maybe a linked list.

Overall do some googling. There is a ton of stuff out there.

Share this post


Link to post
Share on other sites
You cannot use a String data type in a switch statement. So your right there.

There are what is called enumerators. Not sure exactly what your try to do.

If your trying to get a string for the state name and then putting that into your class then use an enumerator.

Are you trying to find the correct object to put some data in then maybe a linked list.

Overall do some googling. There is a ton of stuff out there.

I have only 1 object, I'm trying to get a string for the state name then use a switch statement to determine what the state name is and then set the correct state record to a private variable (named Record). My only question on enumerators is how can I assign more than one string to each number to implement case insensitivity? Like I said above the user may input AL, al, Al, or aL and I want all of them to assign to enumerator "1". Is that possible? I've googled up and down and read and re-read my section on enumerators and haven't found much. Thanks!!!

Share this post


Link to post
Share on other sites
Its been a lot of years since I have written any C code, but, here goes..

I thought that switch evaluates any expression and the expression can be integral or string, so in theory it should work.  Are you using any type of quotes or single ticks?  Is the variable you are using declared globally (if passing to the function)?  You could try parsing the variable to a definition within the function.  This would ensure that the var is assigned within the function and you are not missing an assignment somewhere.

Like I said, been a while.  Haven't written any C code in over 8 or 9 years - was operating system drivers and system resource apps/utilities in UNIX/AIX (similar to windows dll's) for integration of applications (AIX src) within the OS.

One other thought though, putting on my IT architect hat here for a minute..

Although not as sexy as custom code, but MS access or excel should be able to provide the same (if not better) functionality.  Ultimately what you are looking for is data collection and management two things that access and excel do reasonably well for single source.  I know, not as much fun as coding, but think you might get a little more functionality out of it can focus on the function, interface and reporting instead of all the coding.  Can use lists for the states and just input weights, dates and times and output to some custom reports.

Just a thought.

Good luck and let us know how it goes.

Eddie

I don't understand did you just write?  

Share this post


Link to post
Share on other sites
Stick with VB 6 -- its less complicated ... C++ is a pain in the arse

I haven't done any VB for almost 4 years now. I actually wanted to do VB this semester but it didn't fit my schedule so they told me to take C++. I actually like it, but it's definitely tough.

Share this post


Link to post
Share on other sites

Nuclearpenguin (love the name BTW) didn't realize this was for a class.  Sorry.  Still think the switch statement should work.  Talk to your prof and see what they say.

You mentioned about probably not doing a lot of coding after graduation, but, be prepared which sounds like you are doing .  If you go into security probably will not do a lot of coding but could end up editing config files, filters and parsing editors and/or creating simulated load/attacks.  Both of which, depending upon the tool, could look a lot like object-oriented code.

But, sys admin might be a little different story.  

Windows administration probably won't do a lot outside of simple batch scripts as it's mostly automated point and click which is a very good thing.  But, if you do UNIX admin you will probably do quite a bit of code in your career.  In all likelihood it will be shell scripting (ksh, csh, bash, etc.).  I was a UNIX admin for 10 years and wrote more scripts than I can remember.  I wrote a bunch of C code for application integration and utilities that talked/interfaced directly with the operating system.  But, the overwhelming majority of code was shell scripts (ksh).  

So, just be prepared if you go into sys admin, you might do more programming than you realize.  

Good luck,

Eddie

Share this post


Link to post
Share on other sites

Hey, bassin' blvd LOL!

I have found that just like IT, fishing has its own language. I grew up fishing a zebco 202 with nightcrawlers, corn and bread. Several years ago decided I wanted to start fishing again. I find this site and read things like:

Attach a 3/8 chartreuse 5/0 jig-n-pig with a double uni on a med-hvy sensitive tip using a 6.3:1 curado 100d BC with pline ultra in stained milfoil, or, wacky rigged GYCB on the backside of a front for.

Hey, I just want to catch a fish..

I have concluded that we treat everything as a secret society where the innermost secrets and knowledge are shared by code. I think we guys do this to keep the wives/girlfriends/mothers confused Attach a 3/8 chartreuse 5/0 jig-n-pig sounds a lot better that I'm going fishin'. Plus, get to double uni in that statement and my wife has checked out and I'm good for a few hours at the pond.

Share this post


Link to post
Share on other sites

Haha yeah, my name is actually a reference to the Tux so that makes it even better  :P.

I'll ask my prof what he has to say about it. I've done a lot of security stuff before and that's where I had a "little" exposure to c (editing conf files in linux, and also setting up a few exploit files to find the loopholes in my network, etc.) but this is certainly my first semester writing code from scratch.

It's like the difference between being able to  read a foreign language and being able to write a foreign language  ;D

Share this post


Link to post
Share on other sites

When you take the user input just use toLower or conversly toUpper and change them all to the same case before doing any compares.

There is a lot to it. If you try to do a complicated program for your first program it can be overwhelming. Take small steps.

Bite off a bit at a time.

Really, there are many ways to do this and I do not want to send you down the wrong path without knowing a lot more of what your doing.

Try this site http://cplus.about.com/od/learning1/a/cpptutorial.htm

Grab a book that has the basics. Like the one written by Deitel.

Draw a flow chart of your program and then wite each blob.

Share this post


Link to post
Share on other sites
When you take the user input just use toLower or conversly toUpper and change them all to the same case before doing any compares.

There is a lot to it. If you try to do a complicated program for your first program it can be overwhelming. Take small steps.

Bite off a bit at a time.

Really, there are many ways to do this and I do not want to send you down the wrong path without knowing a lot more of what your doing.

Try this site http://cplus.about.com/od/learning1/a/cpptutorial.htm

Grab a book that has the basics. Like the one written by Deitel.

Draw a flow chart of your program and then wite each blob.

I didn't even know about toLower/toUpper. That'll be really useful.

Thanks for the tips! Hopefully I'll be able to press further on this tonight  8-)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • fishing

    fishing forum

    fishing rods

    fishing poles

    fishing reels

    fishing reels

    fishing reels

    fishing

    fishing

    bass fish

    fish for bass
    fish

×
×
  • Create New...