Mastery - Give me a hurdle?

Hello, I am relatively new to C++ (Been reading the documentation for maybe 3 days now?) but not coding in general. (Bit of Basic, but most of my syntax and relative experience comes from using GameMaker 6.0. Not the best place to learn but at least most of these concepts seem somewhat familiar.)

I've read and I believe I understand the concepts up to and through Dynamic Memory, but I can't be sure. Just hoping to have this stuff down pat before I continue to avoid learning something incorrectly and having it mess me up bad later.

Could somebody propose to me a program I could write to see if I really do understand these things? I guess I'm basically asking for homework. If at all possible it would be ideal if it would require very out-of-the-box thinking..

Normally a programming class would have this, but as it is the state of CA schools, they cut our entire computer sci. department down to a typing class and an HTML class...

Also, I've noticed that getline doesn't work correctly with Bloodshed Dev-C++? Maybe something's wrong with my settings but when I used getline instead of cin, the console did not wait for my input and instead closed down (I was under the impression it would wait for my input before continuing the program and reaching the end of main()). Can anyone recommend a good compiler with IDE options for keeping the console window open?

-Nuclei
Last edited on
Write a program that completely loads a file to memory as binary, performs an XOR 0xFF on every bytes, then writes it back.
See the reference for std::istream::seekg(), std::istream::tellg(), std::istream::read(), and std::ostream::write() if you don't know them.
Also, I've noticed that getline doesn't work correctly with Bloodshed Dev-C++
That could be because there's already "something+newline(Enter)" inside input buffer. Try clearing the input buffer then ask for getline. Hope it helps.
Write a program that completely loads a file to memory as binary, performs an XOR 0xFF on every bytes, then writes it back.
See the reference for std::istream::seekg(), std::istream::tellg(), std::istream::read(), and std::ostream::write() if you don't know them.


Ahaha wow alright. I think I may just save the references onto my DS and read up on em at school today.

Thanks Helios. I will post back later today (... Expect a good 14 hours before I post again. School + Swim + Actually attempting.) with my progress.

-Nuclei
Here's an offline reference if you'd like: http://www.cplusplus.com/forum/lounge/9579/
getline() does work in dev c++, i use it alot lately. what are you putting in the '()'?
http://www.wikifortio.com/473195/www.cplusplus.com.7z

Broken link. File no longer exists..
Well; Zomgosh, here's my attempt I guess. I'll upload the first attempt, then I remember 'omg. I forgot to look up those functions.' So then I gave it a second attempt. Links to both follow >.>;;

You can KIND OF see that I was trying to manually set up those functions in my first try lololol... It's no wonder that I failed. Complex and inefficient at best even if I did get it to work I guess. 2nd try works. Spits out a file filled with weird little Y symbols the same length as the first file.

Notes: If you run it, please specify the directory of the new file as well. (C:\Documents and Settings\You\Desktop) <-- Or something of the like.

Epic Failure: http://pastebin.com/f3553d33c
Working one: http://pastebin.com/f54efeb3c

Looking back at that, when I found out there was a nice easy way to accomplish that, the proud 'AHA!' Factor didn't kick in. It was more of a.. 'Oh..' xD..

Ah well.

Is assigning bytes the value of 0xFF diff than an 'XOR 0xFF' ? I have no idea what an XOR is..
Looks perfect, except for the XOR thing.

http://en.wikipedia.org/wiki/XOR#Bitwise_operation

Tip: the operator is ^.
http://pastebin.com/f709c49e2

Is there something like a ^= or the like?

Thanks for the help. I memorized a lot of things that may have eluded me before.
The something= operator exists for all binary operators (+, |, etc.), except for the relational operators (==, <, etc.).
Thanks for the help, Helios.

If it's not too much trouble, could I ask for an objective covering all of the Object Oriented section?
Write a short implementation of a file hierarchy. Small tip: a directory has the same properties as file, and more.
As a bonus, write a function that takes a path and loads to memory the file hierarchy under that path.
Haha sounds a bit complex. I'll post back later with my attempt.
XOR is "The logical operation exclusive disjunction, also called exclusive or (symbolized XOR or EOR), is a type of logical disjunction on two operands ..."

It's the "exclusive OR", meaning it returns true only if ONE of the input values is true, and not both.

Example:

1
2
3
4
5
int one;
if ((one==1 && one!=2) || (one==2 && one!=1)) { /* If one does not equal 2 but equals 1 or
                                                                                    one is equal to 1 but not 2...*/
cout << "One equals: " << one << endl; // print "One equals: [one's value here]";
}
It's the "exclusive OR", meaning it returns true only if ONE of the input values is true, and not both.
Actually, it evaluates to true if an odd number of operators evaluate to true.
what does "performs an XOR 0xFF on every bytes" mean? I know XOR but whats 0xFF
0x is hexadecimal notation. 0xFF is decimal 255.
0xFF is hexidecimal format, FF is equal to an 8 bit-value with ALL bits set to 1.

XORing a byte value with 0xFF essentially flips all the bits in the byte. All bits that were 0 become 1 and all bits that were 1 become zero.
Topic archived. No new replies allowed.