Two Plus Two Publishing LLC Two Plus Two Publishing LLC
 

Go Back   Two Plus Two Poker Forums > >

Notices

Programming Discussions about computer programming

Reply
 
Thread Tools Display Modes
Old 01-17-2015, 03:58 PM   #201
pewpewpew
journeyman
 
Join Date: Dec 2013
Posts: 293
Re: Programming homework and newbie help thread

Quote:
Originally Posted by Benholio View Post
Your current code works fine for me. I think you must have a build problem, like others have suggested. You must be running a stale executable. Try to find any copies of the built executable and delete them all. What IDE are you using? Visual Studio?
yeah, Visual Studio. so just to clarify, in the Debug folder of my project there's a projectname.exe file (the only one i'm aware of) - i should delete it?
pewpewpew is offline   Reply With Quote
Old 01-17-2015, 11:41 PM   #202
Benholio
Carpal \'Tunnel
 
Benholio's Avatar
 
Join Date: Jun 2004
Location: Atlanta, GA
Posts: 8,292
Re: Programming homework and newbie help thread

Quote:
Originally Posted by pewpewpew View Post
yeah, Visual Studio. so just to clarify, in the Debug folder of my project there's a projectname.exe file (the only one i'm aware of) - i should delete it?
Yep.
Benholio is offline   Reply With Quote
Old 01-17-2015, 11:54 PM   #203
well named
poorly undertitled
 
well named's Avatar
 
Join Date: Jun 2007
Location: esse est coesse
Posts: 73,363
Re: Programming homework and newbie help thread

I have two programming rules of thumb

1) when in doubt, use a switch statement
2) write a parser. You know you want to write a parser
well named is offline   Reply With Quote
Old 01-18-2015, 12:09 PM   #204
adios
Carpal \'Tunnel
 
Join Date: Sep 2002
Location: Russian Troll
Posts: 20,896
Re: Programming homework and newbie help thread

Quote:
Originally Posted by well named View Post
I have two programming rules of thumb

1) when in doubt, use a switch statement
2) write a parser. You know you want to write a parser
Yeah that is the direction this is headed. In my view, FWIW, Boost libraries have some convenient and useful libraries for parsing command lines.
adios is offline   Reply With Quote
Old 01-20-2015, 03:56 AM   #205
threatD
centurion
 
Join Date: May 2010
Location: New Zealand
Posts: 173
Re: Programming homework and newbie help thread

Whats the best place to start with learning VBA? Particularly in a Financial background.

Cheers
threatD is offline   Reply With Quote
Old 01-20-2015, 08:21 PM   #206
Craggoo
culled
 
Craggoo's Avatar
 
Join Date: Sep 2006
Location: R.I.P. ItzPenzoo 12-09-11
Posts: 12,251
Re: Programming homework and newbie help thread

Quote:
Originally Posted by Anais View Post
i noticed a little while ago that this thread slowed way down, and it seems like the students have a lot fewer questions now than previously. I'm sure this is just the structure of classes, but it's a pretty cool feeling having all the stuff you learned coming together into one neat little package.

Just did a bunch of functions for a class and then tested it. Worked fine, aside from a small logic error on my part. Just amazed at what a rush it is to solve problems and have an ever-growing arsenal with which to approach these problems.

It's really quite a confidence boost to have taken c++, a language I totally failed at much earlier in my life, and to be getting comfortable with it. Can't wait to know enough to do useful things!

Really hope all the other folks who've been posting here are doing well and haven't given up. Never give up! This is too amazing a field to get discouraged out of!
I think you will find that programming is the type of field that attracts the "never give up" type. Welcome to the club
Craggoo is offline   Reply With Quote
Old 01-21-2015, 07:22 PM   #207
pewpewpew
journeyman
 
Join Date: Dec 2013
Posts: 293
Re: Programming homework and newbie help thread

ahhhhhhhhhdfsgrgdf

i created a new folder in Visual Studio projects to try and organize my programs by the classes i'm taking. i tried dragging a project folder in there, and when i tried opening it the code didn't load.

so i dragged the program folder back out to where it was before and now it still doesn't load, wtf???
pewpewpew is offline   Reply With Quote
Old 01-21-2015, 07:36 PM   #208
ChrisV
Carpal \'Tunnel
 
ChrisV's Avatar
 
Join Date: Jul 2004
Location: Adelaide, Australia
Posts: 34,601
Re: Programming homework and newbie help thread

Open the .sln and .csproj files in an editor and check that any and all paths therein are correct.
ChrisV is offline   Reply With Quote
Old 01-21-2015, 07:45 PM   #209
pewpewpew
journeyman
 
Join Date: Dec 2013
Posts: 293
Re: Programming homework and newbie help thread

hmm well the .sln is the thing i was trying to open that didn't work. i tried opening .vcxproj (assume this is what .csproj refers to since i can't find that) and it's the same thing - no code, and the area to input the code is blanked out like there's no project loaded.
pewpewpew is offline   Reply With Quote
Old 01-21-2015, 08:00 PM   #210
pewpewpew
journeyman
 
Join Date: Dec 2013
Posts: 293
Re: Programming homework and newbie help thread

ok now i tried creating a completely unrelated new project and the same thing happens, no place to enter text...LOL i have no idea what i'm doing:

pewpewpew is offline   Reply With Quote
Old 01-21-2015, 08:00 PM   #211
adios
Carpal \'Tunnel
 
Join Date: Sep 2002
Location: Russian Troll
Posts: 20,896
Re: Programming homework and newbie help thread

Quote:
Originally Posted by pewpewpew View Post
ahhhhhhhhhdfsgrgdf

i created a new folder in Visual Studio projects to try and organize my programs by the classes i'm taking. i tried dragging a project folder in there, and when i tried opening it the code didn't load.

so i dragged the program folder back out to where it was before and now it still doesn't load, wtf???
"the code didn't load" means what? You could not open your source file? You couldn't build the solution? You couldn't execute the program?

Not sure what version of VS you are using, what error message are you getting including error number. I am not an expert on VS but I'm guessing your default paths for linking and include files are messed up. I think you can right click on the solutions pane to set inspect what they are and change them if need be.
adios is offline   Reply With Quote
Old 01-21-2015, 08:05 PM   #212
adios
Carpal \'Tunnel
 
Join Date: Sep 2002
Location: Russian Troll
Posts: 20,896
Re: Programming homework and newbie help thread

Quote:
Originally Posted by pewpewpew View Post
ok now i tried creating a completely unrelated new project and the same thing happens, no place to enter text...LOL i have no idea what i'm doing:

LOL yeah some things with VS are maddening. Try clicking on that solutions explorer tab. I think there's some menu selection where you restore VS back to its original state.
adios is offline   Reply With Quote
Old 01-21-2015, 08:07 PM   #213
pewpewpew
journeyman
 
Join Date: Dec 2013
Posts: 293
Re: Programming homework and newbie help thread

Quote:
Originally Posted by adios View Post
"the code didn't load" means what? You could not open your source file? You couldn't build the solution? You couldn't execute the program?

Not sure what version of VS you are using, what error message are you getting including error number. I am not an expert on VS but I'm guessing your default paths for linking and include files are messed up. I think you can right click on the solutions pane to set inspect what they are and change them if need be.
sorry, i meant the when i try to open .sln or .vcxproj, Visual Studio opens but the code i wrote is no longer there (and now when i try to create a new project, there's not even a place to enter code). there's no error message, it just looks like the photo in my previous post when i try to open or create a new file in VS now.

edit - since you mentioned it and i'd never tried it before, i tried going straight to the .cpp source file....and it opened in CodeBlocks, with all my code there! which is kind of bizarre to me, because i have CodeBlocks installed, but never written anything in it, and the source was from my Visual Studio projects folder.....huh?
pewpewpew is offline   Reply With Quote
Old 01-21-2015, 08:15 PM   #214
pewpewpew
journeyman
 
Join Date: Dec 2013
Posts: 293
Re: Programming homework and newbie help thread

urff yeah...the solutions explorer solved it, thanks. somehow that menu got minimized and without it being in its regular spot i forgot i needed to make a cpp file -_-

so back to being able to create new projects...still not sure why my saved code .sln file wouldn't open in VS and randomly opened in CodeBlocks when i opened the source.
pewpewpew is offline   Reply With Quote
Old 01-23-2015, 01:11 PM   #215
pewpewpew
journeyman
 
Join Date: Dec 2013
Posts: 293
Re: Programming homework and newbie help thread

i'm completely lost on this assignment. directions:

Quote:
"Write the class used to monitor the gas tank in a car. The gas tank should have two constructors. One constructor should create a tank that holds twenty gallons. The other constructor should be passed the size of the tank. The tank will be empty after creation. The class will also have a function called fill which should fill up the tank and return the number of gallons filled. There should be a procedure called used which should take gas out of the tank. This procedure should be passed the number of gallons used. The class will also have a function to tell the user if the fuel is getting low. The fuel is low if there is only 25% of the fuel left. The last function will tell the user how many gallons are left in the tank."

Example Output:

Gallons filled tank 1 -> 20
Gallons filled tank 2 -> 5
fuel OK
Low fuel light
gallons left -> 4
Gallons filled tank 1 -> 16
Gallons filled tank 2 -> 0
this is what i have for my main, not running anything yet because i can't figure out the Class functions part at all:

Code:
void main()
{
	Gastank tank1(0);
	tank1.fill();
	Gastank tank2(5);
        tank2.fill();

	cout << "Gallons filled tank 1 ->" << tank1.fill() << endl;
	cout << "Gallons filled tank 2 ->" << tank2.fill() << endl;

	tank1.used(10);

	if (tank1.low())
	{
		cout << "Low fuel light" << endl;
		cout << "gallons left ->" << tank1.left() << endl;
	}
	else
		cout << "fuel OK";
	
	cout << "Gallons filled tank 1 ->" << tank1.fill() << endl;
	cout << "Gallons filled tank 2 ->" << tank2.fill() << endl;
}
i'm having trouble figuring out how to get all my objects passed through my procedures/functions/whatever at the right times.

so here's one of the several things i tried putting for my class at the top of the program, i'm pretty sure it's several orbits away from anything resembling "correct":

Code:
class Gastank{
	public:
		Gastank(int x){

		};

		Gastank(int y){
			x = y;
			currentLevel = y;
		}
	private:
		int fill(int y){
			int p;
			p += 1;
			y += 1;
			return y;
		}
		void used(int p){
			int gasUsed;
			gasUsed += p;
		}
		int left(){
			int gasLeft = (20 - gasUsed);
			return gasLeft;
		}
		bool low(int){
			int currentLevel;
			if (currentLevel <= 5){
			}
};
pewpewpew is offline   Reply With Quote
Old 01-23-2015, 02:43 PM   #216
KatoKrazy
veteran
 
KatoKrazy's Avatar
 
Join Date: Jan 2009
Posts: 3,174
Re: Programming homework and newbie help thread

Replying from my phone, but some basic comments:
Default constructor should take no param
Why are all your functions private?
You are going to want to define some private member variables such as capacity, currentFuelLevel, lowFuelLevel
Your function low can just return currentFuelLevel lte lowFuelLevel
Low fuel level can be set in the constructor
KatoKrazy is offline   Reply With Quote
Old 01-23-2015, 03:11 PM   #217
adios
Carpal \'Tunnel
 
Join Date: Sep 2002
Location: Russian Troll
Posts: 20,896
Re: Programming homework and newbie help thread

Quote:
Originally Posted by KatoKrazy View Post
Replying from my phone, but some basic comments:
Default constructor should take no param
Why are all your functions private?
You are going to want to define some private member variables such as capacity, currentFuelLevel, lowFuelLevel
Your function low can just return currentFuelLevel lte lowFuelLevel
Low fuel level can be set in the constructor
This

plus

The way you have declared gasUsed it is an automatic variable where the scope is limited to the method that declared it. You need to make the scope class wide.

a private attribute for the size of the tank.

a private attribute for the amount left in the tank. (you can calculate gas used from this value if you want to).

public access methods for the attributes defined above.

Should you be using the int type for the amounts? It seems reasonable to me that fuel amounts are better represented when fractional amounts are accounted for somehow. Do you need to check for negative value inputs to your use method?

Stuff like that.


You don't have to but I would tend to put the class definition in a .h file and the methods in a .cpp file.
adios is offline   Reply With Quote
Old 01-23-2015, 04:20 PM   #218
pewpewpew
journeyman
 
Join Date: Dec 2013
Posts: 293
Re: Programming homework and newbie help thread

regarding the functions being private, our instructor told us to keep the data in classes private as a general rule, but maybe i misinterpreted what he meant.

by default constructor you mean the first constructor?
pewpewpew is offline   Reply With Quote
Old 01-23-2015, 05:00 PM   #219
KatoKrazy
veteran
 
KatoKrazy's Avatar
 
Join Date: Jan 2009
Posts: 3,174
Re: Programming homework and newbie help thread

Right. The one that defaults the tank to 20 gallons.

In regards to your functions... If you make them private nobody outside your class can call them, rendering them useless.
KatoKrazy is offline   Reply With Quote
Old 01-23-2015, 06:03 PM   #220
Anais
Carpal \'Tunnel
 
Anais's Avatar
 
Join Date: Mar 2006
Posts: 6,666
Re: Programming homework and newbie help thread

our instructor told us that classes have data and methods, and to keep the data private.
Anais is offline   Reply With Quote
Old 01-23-2015, 09:02 PM   #221
ChrisV
Carpal \'Tunnel
 
ChrisV's Avatar
 
Join Date: Jul 2004
Location: Adelaide, Australia
Posts: 34,601
Re: Programming homework and newbie help thread

Quote:
Originally Posted by pewpewpew View Post
by default constructor you mean the first constructor?
A default constructor is one that takes no parameters. The 20 gallon tank constructor should not take any parameters because it doesn't need to be passed any information.

Quote:
Originally Posted by Anais View Post
our instructor told us that classes have data and methods, and to keep the data private.
Quote:
Originally Posted by pewpewpew View Post
regarding the functions being private, our instructor told us to keep the data in classes private as a general rule, but maybe i misinterpreted what he meant.
Just saying that and not explaining why doesn't seem like great teaching.

What should be kept private is implementation. The first car I owned didn't have power steering. When I upgraded to one that did, what happened behind the scenes when I turned the wheel was very different, but I didn't have to relearn anything. I still just turned the wheel and the car changed direction. This is an example of the implementation being hidden from me.

The reason data should be kept private is that data is always an implementation detail. For instance, your gastank class is keeping track of how much fuel is in it by storing a number, but there's no reason that would have to be the case for a gas tank. It could, for instance, calculate how much fuel is left from the weight of the tank. If you expose that stored number directly, then if you want to start calculating it with a method instead, it will break code that is using your class, which expects to be accessing an integer directly and not calling a method. Instead you should make the number itself private and expose it with a public method (or property, depending on the language). That way, changing how that number is provided just involves changing the code inside the method, and any code calling it can stay blissfully unaware that the implementation has changed.

"On request, I will tell you how much gas is left in me" is an abstraction. "I do this by internally keeping track of a number" is implementation. Abstractions public, implementations private.
ChrisV is offline   Reply With Quote
Old 01-23-2015, 09:43 PM   #222
pewpewpew
journeyman
 
Join Date: Dec 2013
Posts: 293
Re: Programming homework and newbie help thread

thanks for the explanations guys, much appreciated.

i have to side-track back to my earlier project (converting temps from Celsius to Fahrenheit or vice versa) since i forgot the deadline is a few hours from now -_-

basically it's done, but it keeps closing whenever i run it. i can put system("pause") at the end (i've been doing that for the sake of running it) but it seems kind of silly. just need it to stop closing so i can zip it and send it in :S

Code:
#include <iostream>
using namespace std;

float main(int argc, char argv)
{
	float temp;
	char convert;

	cout << "Enter a temperature: ";
	cin >> temp;
	cout << "Press 'c' to convert Fahrenheit to Celsius. Press 'f' to convert Celsius to Fahrenheit. ";
	cin >> convert;

	if ('c' == convert)
	{
		float ftemp, ctemp;
		ftemp = temp;
		ctemp = (ftemp - 32) / 1.8;
		cout << "The Fahrenheit temperature (" << temp << ") is \"equivalent\" to the Celsius temperature (" << ctemp << "). ";
	}
	else if ('f' == convert)
	{
		float ftemp, ctemp;
		ctemp = temp;
		ftemp = ctemp * 1.8 + 32;
		cout << "The Celsius temperature (" << temp << ") is \"equivalent\" to the Fahrenheit temperature (" << ftemp << "). ";
	}
	else
	{
		cout << "Invalid input. ";
	}
}
pewpewpew is offline   Reply With Quote
Old 01-23-2015, 10:14 PM   #223
KatoKrazy
veteran
 
KatoKrazy's Avatar
 
Join Date: Jan 2009
Posts: 3,174
Re: Programming homework and newbie help thread

Just keep system pause or a cin. It will close otherwise.

Last edited by KatoKrazy; 01-23-2015 at 10:19 PM.
KatoKrazy is offline   Reply With Quote
Old 01-23-2015, 10:44 PM   #224
adios
Carpal \'Tunnel
 
Join Date: Sep 2002
Location: Russian Troll
Posts: 20,896
Re: Programming homework and newbie help thread

Quote:
Originally Posted by pewpewpew View Post
regarding the functions being private, our instructor told us to keep the data in classes private as a general rule, but maybe i misinterpreted what he meant.
Quote:
Originally Posted by Anais View Post
our instructor told us that classes have data and methods, and to keep the data private.
He is referring to a concept called encapsulation.
adios is offline   Reply With Quote
Old 01-24-2015, 08:04 AM   #225
catsec
centurion
 
catsec's Avatar
 
Join Date: Apr 2014
Location: hunting shells
Posts: 179
Re: Programming homework and newbie help thread

I'm taking a cryptography class and we're required to write a program in python (3) to decrypt a message encrypted with the Caesar cipher. It's encrypted with a shift of 3, but we're to prompt the user to input the shift value.

I know exactly how the Caesar cipher works and can decrypt the message by hand, but I'm not very good with programming and can't figure out where to go from where I'm at.

Code:
cipherText = "FRQJUDWXODWLRKVBRXKDYHGHFOBSWHGWKHPHVVDJH"
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
shiftValue = input("Please enter an integer shift value from 1 to 26: ")
decryptedText = ""

def checkShift():
    if shiftValue.isdigit() == True:
        print(shiftValue)
    else:
        print("Please only enter an integer. ")
        checkShift()

def decryptCipher():
    for char in cipherText:
        if char in alphabet:
            print(char)

checkShift()
decryptCipher()

So basically all I've got at the moment is the cipher text, the alphabet, I'm prompting the user to input the shift and I'm checking to see if it's an integer and printing for debugging. I'm also checking to see if the characters in the ciphertext are in the alphabet and printing for debugging. Finally I have an empty string to store the decrypted text in for printing out.

Regarding the checkShift function, in addition to checking to make sure it's an integer, I'd also like to check to see if the integer is greater than zero and less than 27, but I'm unsure how to code that into the function.

Regarding the decryptCipher function, I know I need to pass the shift value to the function and check the cipher text's characters against the alphabet plus that shift and then add those characters to the empty string, but I can't figure out how to do that.

Any help is greatly appreciated.
catsec is offline   Reply With Quote

Reply
      

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Forum Jump


All times are GMT -4. The time now is 04:34 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © 2008-2017, Two Plus Two Interactive
 
 
Poker Players - Streaming Live Online