jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Did you mean to put M instead of r in your macro?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

[code] //code goes here [/code]
(akin to an HTML tag but with [] instead)
or you can highlight your code in the editing box and click on the

icon in the toolbar.

Look at the writing on the background of the Quick Reply box. It's also in the documentation when you first sign up. There's a large bold blue announcement about it in every forum. When you received the notification the first time from the moderator there was documentation in the PM as to how to do it. I had sent you a PM as a courtesy about it.

It's crucial but especially so when you are posting large code samples to have the formatting intact (posting it as plain text strips all the leading spaces and makes a mess).[code]
icon in the toolbar.

Look at the writing on the background of the Quick Reply box. It's also in the documentation when you first sign up. There's a large bold blue announcement about it in every forum. When you received the notification the first time from the moderator there was documentation in the PM as to how to do it. I had sent you a PM as a courtesy about it.

It's crucial but especially so when you are posting large code samples to have the formatting intact (posting it as plain text strips all the leading spaces and makes a mess).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

My password is always the day of the week my password was created. I tell people that, too, because it's not like they'll know what day of the week I created it. That makes it secure. Extremely secure.

And assuming you don't vary case, there's like 10 to the.... er 2 to the... oh wait there's only seven things to guess. They'll never catch on. :) (it's more fun if you weren't kidding)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Probably more than 3/4 (just a guesstimate) of any Windows programming requires non-standard extensions to C++. So trying to learn C++ that way would be like trying to derive the rules of grammar from a (hypothetical) variant of English that's highly dialected and loaded with slang.

That being said, there are tutorials out there. Available via Creative Commons is C++ GUI Programming Using Qt4 (here) that I would say is "accessible" to a beginner but contains many idioms within the code to drive the process of GUI building (their own macros for example).

And of course there's Win32 and MFC (MFC not being available on the Express Editions of the Visual C++ compiler) as well as CLR/Winforms (which really messes with the C++ syntax and makes it more like C# for .NET integration).

I'm sure I've omitted some possibilities but my overall message is, take some time now, learn the language (and it's quirks and gotchas). Then, look into a book like this which I've honestly never read but people speak very highly of it (there's a 2010 edition coming out at some point). Check out the books sticky thread on the forum but I've forgotten if there are any GUI books there.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

That is correct, if you use rand() % 6 + 1 you will be good. Also, when you define a function:

Yes, to get numbers from 1 to 6 that is what you would do, but he's stored them in array (zero based) so you don't need the +1.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

But what I find odd is that the error says it can't find a constructor with a char const* but isn't it supposed to be const char*?

It's a case where the pointer is const but the value of the char is not.
See http://www.daniweb.com/forums/post1094084.html#post1094084 and in fact the whole thread is good. Bad news is, I'm not sure what that means for your filename variable necessarily but try defining the filename variable as char const *

I had thought about the default values thing and as I study it more closely it seems like you are correct about that.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

rand() % 7 is going to get you numbers between 0 and 6 which will overstep the bounds of your array by 1 if a 6 is pulled.

I'm confused why you broke up the loop like you did?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm not so sure about that... They seem to be pretty much the same to me.

I meant strings as more well behaved with cin >> but I didn't clarify that. Apologies.

Probably because in C++ char arrays are necessary at times, but strings are somewhat more standard and have more functions(methods) to deal with them easier. They are also dynamic.

Well put.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Is there a specific reason that you are using a string instead of char array? It would be easiest with an array because of how you can manipulate it

Having to know how many chars you need ahead of time is a biggie. I think strings behave a bit better with cin than char arrays. If he/she was already using strings in his code he/she should continue using them.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

jonsca couldnt he just do this
? yes i changed it around.

We were getting there but yes, except it's input.length()-1 for the starting index. Try not to give too much away so the OP can learn...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Are you using asserts? Something doesn't seem right there.

Also cout<<line[5],line[4],line[3],line[2],line[1],line[0]; is not correct, you need the << between each character.

For code tags it's easy, either type [code] //your code in the middle[/code] just like using html tags but with [] or you can highlight your code in the editor and click on the [code] button in the toolbar.

EDIT: I goofed on my noparse

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What's the error? Display the segment of code from where it originates.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Make line into a string, though (unless you have to use the char arrays but they are old and clunky)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You were trying to do it with pointers which is overcomplicating things. Just address it by word[0], word[1],word[2] etc. You don't have to know what the user will input if you get the string length using that function that I showed you earlier. mystr = "hello"; myst.length() is equal to 5, but remember that the index of 'o' is 4 is all. Can you generalize that?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Dude, no one's going to laugh at you. Code tags would be nice, though. I'm going to echo a bit of what Walt P was saying. If you are saying that you want to display your string in reverse you don't need to store it like that you just have to output the characters in reverse.
What I mean is that in a string mystr = "hello" you can access h as mystr[0], e as mystr[1], etc. and you can find the length of a string by mystr.length() (it's= 5) where in both cases mystr is the name of your string. So armed with the above information write out on paper the indexes that you need to reverse the string "hello" based on its length (i.e. what index is o, what index is l, etc).


-------------------------
(Post 1000) - Ignore this

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you are not allowed to use the Standard Template Library (STL) a big hint is that you can treat a string as an array of characters.

EDIT: To your last question, you have to #include <algorithm> for that to work.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

From: http://developer.kde.org/~wheeler/taglib/api/classTagLib_1_1FileRef.html

I've never used this library but it seems like you need a file pointer (FILE * like from fopen) for the constructor taking 1 argument. The 3 argument constructor seems to take a filename. When you eliminate the parameter from FileRef you are evoking the default, so itwould go through without a hitch.

This may not be the problem but I figured it was worth noting.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

variables number and value are not declared.

Thanks Rahul, I'm not sure how I zoned out on that one.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

@evsteve Check out Precompiled headers

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Not for the console app (which is the best setup for programs like you had initially), but for the Win32 program setup that's exactly the type of thing you need. Console app has a main() function.
There are arguments either way but it's usually easier to get the language down pat with the console stuff first...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Select Win32 Console App (and while at that uncheck use precompiled headers and leave empty project unchecked). That should get you started with it. I don't know if you can change it after it's been created, just start a new one.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Woh, thanks you have been extremely helpful

Hey, no problem at all. Definitely post back with further questions on this.

Are you talking about making a program in a window instead of the console? You'll probably want to polish your basics a bit but look at http://www.winprog.org/tutorial/ for Win32 (MS has other window frameworks but Win32 is the most fundamental). There are other toolkits like Qt and wxWidgets that can be used with other compilers.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you're wanting to learn something directly applicable, read about switches. It's almost like a shortcut to writing systems of nested if else statements. Check out:http://www.fredosaurus.com/notes-cpp/statements/switch.html
I suggested the arrays because it would be nice to store your usernames in one array and passwords in another so you can compare usernames to passwords easily.
I suggested functions because it might be nice to have a function to govern the login so that you're not dealing with the password verification stuff in the main function.
Neither of the two things above is really required, though.
So you're really free to do however much you want with it. If it is one of your first few projects, keep it reasonably simple. Also, it helps to make a piece of it first, test that out then add another piece.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You can do it but it will require a lot of nested if statements. You could either have a command on each level and have the user only exit one level at a time --> e.g., login -> choose menu item 1 ->into menu 2->exit->back to first menu->exit->logged out -or- you could just call exit(0) whenever the user types in exit. The latter may become more error prone.
Is "if" statements the only thing you have covered so far? Anything with arrays or functions? Those two things might make this slightly easier.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

3. How can l add a commend after each prompt that if it is not the same as the the (getinput=="~~~") it goes back to the start?

Can you clarify what you mean by this?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Or do I do this?

Well, your last one was closest. If you are permitted to pass additional parameters I would go with:

void AskForTwoNames(string &rNameONE, string &rNameTWO)
{
            cout <<"Enter name 1: ";
            cin >> NameONE; //or getline but don't mix cin/getline
             //if you do cin then getline you'll have extra chars in the stream
            //which you could sweep up with an ignore statement like
             //you have but it's extra hassle
            cout <<"\nEnter name2";
            cin >> NameTWO; //or getline but see above
}

That way you're not taking them in one at a time and making one string only to split it again in your search step (unless like I said if you were restricted to passing 1 parameter only).

Just for comparison's sake (and to point out the substr):
What I did (assuming the you couldn't pass in the two strings) was within your WriteOutput:

int index = rUserInput.find(" ");
	string name1 = rUserInput.substr(0,index-1);
	string name2 = rUserInput.substr(index+1);

find(" ") returns the zero-based index of the first space in your string, then I took the substring from 0 of length index -1 (so in the string "Adam Smith" the space would be found at index 4, so I'd take 4 chars starting from zero) and then took another substring from the character after the space until the end (S is at position 5 to the end -- so if you took substr(0) you'd end up with your whole string again). See this …

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If find() doesn't find what I want, then found == string::npos else it outputs an integral value.what does that integral value meanns??

http://www.cplusplus.com/reference/string/string/find/
It's the index of the first occurrence of the string stored in word within your line of text that you have read in. So a multiple line file will yield a value for found for each line. However, find is able to locate your search word within another word of the text, e.g., if you are looking for "the" and the word "anthem" is in your text.

if the specified word is found then i want to display the attributes of that text file , like its name , size , directory etc.

Well filename is quite easy as you already have it from the user. The other information you'll have to get in an OS dependent way. I am assuming you are using windows but there are functions in *nix to accomplish the same thing. Search around the forums for some pointers, but you can look up the documentation for io.h or take a look at this for the specific Win32 functions for file handling (you'll have to include windows.h and make sure to designate your project as a Win32 Console app to make sure you have all the appropriate libraries).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Just a couple of changes:

my_file.open ((getname()+ext).c_str());  // need a c-string for this
		//you can delete { that was on this line and its match	
	            if (my_file.is_open())  //this is ok, included just for context			
		   {				
			while (getline (my_file,line))
			{  //see post #7 where Lerner explained

With those changes it worked just fine for me. Output a space after found in your highlighted code to see the indexes.

As far as the file attributes go, which do you need? You have included io.h which you can use but the caveat is that most of those functions are non-portable. You can find a reference for it with your compiler docs or there seem to be a few out there on the web (make sure it matches your implementation).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

All pop up ads must be true. ;)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I guess when you retake the course next term you'll have to ask a lot more questions and seek clarification.

Well, to reiterate no one is going to just hand you a project.

Start looking at examples of code out there on the net. Try to recreate some of the simpler ones and see how far you get. AncientDragon is 1000% correct though, it's a mighty push to learn the basics of C in an entire term let alone 3 days.

Salem commented: *agrees* +19
tux4life commented: *agrees* +6
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you set it up like tkud recommended (his second approach), it looks like you might have wanted to compare if(ret !=0) , right?

However, a (somewhat) brief explanation of what the compiler was trying to tell you:
Your class must overload the != if you are going to use it to compare your objects directly like you would an int or bool. For example if you had a person class with age and you wanted to say two people objects were equal based on their age, you would overload == (and != as well just as the not of ==).
So saying person1 == person2 would be the same as saying person1.age == person2.age, you can compare the objects directly.
Look up operator overloading there's tons of other examples out there.

EDIT: LOL niek_e beat me to it

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

1.) Find some tutorials on the web (read and reread the 'Starting C' sticky thread in this forum

2.) Get a book with lots of examples

3.) After you've started writing some code, post back with your attempt and people will be able to help you

I always find it hard to believe that they would expect you to do a project in a class after not covering any of the material in the course.

In any case, those are your deadlines and the burden is on you to get what you need to achieve your goal.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

When you are choosing the type of project in the beginning are you doing Win32 or CLR/Winforms?

Also, during that project selection process did you check the box saying empty project? If you check that many settings will not be correct without manually changing them.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'd put it in a 2D array. That way you can iterate over the rows and pick a random die face from each to face "up". Making your swaps with 16 different arrays could turn into a nightmare. I don't have too much to add besides that. Sounds like a neat (and doable) project!

Definitely post back if you have any further questions about it and hopefully you'll get some other suggestions on this thread.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You're missing a return value (in the generic sense) which in this case happens to be the variable value.

Put in return value; between lines 26 and 27.

Not as critical, but you never use the parameter of the function for anything.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

In the first example with cin >> age; Say you type in 20 and Enter. 20 gets read into your int and the newline ('\n') from the enter remains in the input stream.
getline is designed to read until a newline occurs (which it reads and discards), so as it comes along and reads the stream it hits \n right away and quits thinking its got what it was looking for, so your code effectively skips down to your next newline.

What firstPerson has prescribed is putting in a getline to sop up that extra newline so the stream is fresh for the subsequent real getline. A call to cin.ignore(); can be used for the same purpose as his added getline.

So in the second piece of code you've taken up the first string (including newline) but disposed of \n before the next call to getline.

EDIT: firstPerson beat me to it :)

EDIT II: You probably don't even need to deal with the getline and just cin >> yourstring;

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Did you try googling "flow charts" or "flow charting"? There are a bunch of links and most of them have the symbols. Happy hunting.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You need to add currentMonth to your private variables list up in the declaration. You currently have string month[20]; which is giving you an array of 20 strings.
So either change "currentMonth" to "month" in your setMonth method or declare currentMonth up with the other private variables and delete string month[20] (the latter is probably the best).

You have no method getMonth() defined, you just have it declared.

Also, it's a little confusing to us when you make 3 different posts as people are recommending solutions on all of them and you're not incorporating them in each version. It's nice to want to split it up by topic but IMO makes it less organized when dealing with the same piece of code.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

DS, I completely agree. I was attempting to help the OP in the context of his assignment. I wasn't sure what if any restrictions were in place but I made some assumptions.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Ok I got everything functioning properly, I just haven't been able to get the search to work properly. What should I do? Is there a specific method I should use?

You need to split the string rUserInput into name one and name two, you can do that with the string functions themselves (hint: substr). Next look up binary search (http://en.wikipedia.org/wiki/Binary_search_algorithm).

Since you've sorted your names list already you more than likely need a binary search. You can start at the middle of the list and see if the name you are searching for is "higher" or "lower" (with std::string you can use the < > == operators). If it's in the upper half, go to the middle of that part of the list and see if it's in the higher portion of the upper half or the lower portion of the upper half , etc., keep splitting it until you find the element or until you get to 1 non-matching element (at that point you haven't matched it).

|                             x|                y|        z|         |
(so is it less than or greater than element x?  say greater
 go to y
is it less than or greater than y? greater
go to z
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Now this will take care of the Boolean statement and if statement, and complete both of those in one summed up code:
Correct?

Correct. There's never a need to do if(xyz == false), you just do if(!xyz), since if xyz is false, !xyz will be true and if(true) will follow the code after the if statement.

Since your method returns a boolean you get it all done in one step. It doesn't always pay to cram everything down into one but in this case IMHO, most people prefer to see it this way then to have to go back and check.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Unfortunately you've stumbled upon a problem inherent in floating point computations. See http://en.wikipedia.org/wiki/Floating_point#Representable_numbers.2C_conversion_and_rounding . Try using a double -- there's really no reason to use float these days unless you're trying to cram numbers in as tightly as you can and if your precision requirements aren't very strict.

(See the wiki articles on "double precision floating-point" and "single precision floating-point" or search for "IEEE 754" if you're interested)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Any time you are declaring a method it should have the type in front of each of the parameters (e.g., int gBill). But I think what you've meant to do is leave the friend declaration right where it is and move line 27 out with your method definitions, but you won't precede it with a expense:: since it is a friend function. Bear in mind that if your friend function is private you will only be able to run it from one of the other methods in your class.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You have the income and you have the expenses... All this method will do is update your savings variable, nothing in or out.

Also, it says to have a month member variable, you are missing that.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
[B]Declaration:[/B] -- what it will take in and return
void display();  //line 16 -- part of your class declaration lines 7-25

[B]Definition: [/B] -- the actual mechanics of the method
void expense::display()  //line 27
{
        cout <<"expense"<<","<<getEBill<<","<<getGBill<<","<<getWBill;
}

So fix up lines 18-21 appropriately. What parameter do they all take in?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I have copied the exe found in the debug folder

A little late on my part as the discussion has shifted but it's probably worth noting that you definitely want the Release build exe and not the Debug version as it debug has all of the extra luggage (debug info) inside (and is not optimized).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The declaration of these methods is incorrect (the definitions are fine)

void setEBill();
void setWBill();
void setGBill();
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What have you tried so far? It will be helpful to know the layout of the input file also.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You toggled the bits perfectly but I don't see where you add in the 1... It won't be much work, just make sure to carry the 1 along (so like 01111 base 2 + 0001base two will be 1+1 = 10 (mark 0 down), carry the one 1+1 = 10, (mark 0 down) carry the one, etc. It doesn't usually propagate too far in. You can check your answers with a small program where you set an int to the value of your binary string in hex and then display it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Here's one of your methods.

void expense::getGBill(int i)
{
     gbill=i;
     return gbill;
     
     }

It neither gets nor sets it's somewhere in the middle so it does nothing. If you have a private member variable such as gbill in the above case you need gatekeepers to make sure you can access the information but only on your terms. Your getter for gbill simply returns the value of gbill to the caller. It doesn't need to take in any parameters as it's returning what already exists (in this case gbill) within the object of the class. So, you need a getter that's returning something. What does void return? Nothing. So your get method should return an int (the type of gbill).

The setter, which has to be a separate method from the getter, takes in a value (of the same type as gbill and sets the private variable gbill to that value. This method will be void.

I'll leave the implementation up to you since I've given you quite a bit of it but your calls in main() would look something like this:

int gbill_in;
int gbill_out;
expense exp;
gbill_in = 20; //I'm just making this one up could come from input
exp.setGBill(gbill_in);    //void method
//say here you invoked another method that changed
//that private value internally
exp.someMethod();
//now get gbill again
gbill_out = exp.getGBill();  //returns an int