Open Side Menu Go to the Top
Register
Programming homework and newbie help thread Programming homework and newbie help thread

01-17-2015 , 03:58 PM
Quote:
Originally Posted by Benholio
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?
Programming homework and newbie help thread Quote
01-17-2015 , 11:41 PM
Quote:
Originally Posted by pewpewpew
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.
Programming homework and newbie help thread Quote
01-17-2015 , 11:54 PM
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
Programming homework and newbie help thread Quote
01-18-2015 , 12:09 PM
Quote:
Originally Posted by well named
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.
Programming homework and newbie help thread Quote
01-20-2015 , 03:56 AM
Whats the best place to start with learning VBA? Particularly in a Financial background.

Cheers
Programming homework and newbie help thread Quote
01-20-2015 , 08:21 PM
Quote:
Originally Posted by Anais
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
Programming homework and newbie help thread Quote
01-21-2015 , 07:22 PM
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???
Programming homework and newbie help thread Quote
01-21-2015 , 07:36 PM
Open the .sln and .csproj files in an editor and check that any and all paths therein are correct.
Programming homework and newbie help thread Quote
01-21-2015 , 07:45 PM
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.
Programming homework and newbie help thread Quote
01-21-2015 , 08:00 PM
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:

Programming homework and newbie help thread Quote
01-21-2015 , 08:00 PM
Quote:
Originally Posted by pewpewpew
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.
Programming homework and newbie help thread Quote
01-21-2015 , 08:05 PM
Quote:
Originally Posted by pewpewpew
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.
Programming homework and newbie help thread Quote
01-21-2015 , 08:07 PM
Quote:
Originally Posted by adios
"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?
Programming homework and newbie help thread Quote
01-21-2015 , 08:15 PM
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.
Programming homework and newbie help thread Quote
01-23-2015 , 01:11 PM
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){
			}
};
Programming homework and newbie help thread Quote
01-23-2015 , 02:43 PM
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
Programming homework and newbie help thread Quote
01-23-2015 , 03:11 PM
Quote:
Originally Posted by KatoKrazy
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.
Programming homework and newbie help thread Quote
01-23-2015 , 04:20 PM
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?
Programming homework and newbie help thread Quote
01-23-2015 , 05:00 PM
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.
Programming homework and newbie help thread Quote
01-23-2015 , 06:03 PM
our instructor told us that classes have data and methods, and to keep the data private.
Programming homework and newbie help thread Quote
01-23-2015 , 09:02 PM
Quote:
Originally Posted by pewpewpew
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
our instructor told us that classes have data and methods, and to keep the data private.
Quote:
Originally Posted by pewpewpew
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.
Programming homework and newbie help thread Quote
01-23-2015 , 09:43 PM
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. ";
	}
}
Programming homework and newbie help thread Quote
01-23-2015 , 10:14 PM
Just keep system pause or a cin. It will close otherwise.

Last edited by KatoKrazy; 01-23-2015 at 10:19 PM.
Programming homework and newbie help thread Quote
01-23-2015 , 10:44 PM
Quote:
Originally Posted by pewpewpew
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
our instructor told us that classes have data and methods, and to keep the data private.
He is referring to a concept called encapsulation.
Programming homework and newbie help thread Quote
01-24-2015 , 08:04 AM
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.
Programming homework and newbie help thread Quote

      
m