Welcome
Welcome to the forums of AntiRTFM's Absolute N00b Spoonfeed C++ Tutorials!

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. Registration is fast, simple, and absolutely free, so please, <a href="/profile.php?mode=register">join our community today</a>!

Practice Stuff

Got an idea for a practice project / debug snippet / short-code contest / etc? Tell us about it here!

Practice Stuff

Postby Altromer521 on Wed Oct 15, 2008 1:50 pm

Hey all,
I am currently in a class for school where we are learning c++, I have also taken classes before. Anyways, I have a bunch of material from the books and class I have taken for practice. Such as projects, debug and all that good stuff. If you guys would like this let me know and when I get a chance I'll start posting it up.
Altromer521
 
Posts: 3
Joined: Wed Oct 08, 2008 1:12 pm

Re: Practice Stuff

Postby antiRTFM on Wed Oct 15, 2008 9:21 pm

By all means, please go ahead!
User avatar
antiRTFM
Administrator
 
Posts: 462
Joined: Sun Apr 13, 2008 9:10 am

Re: Practice Stuff

Postby Altromer521 on Sat Oct 18, 2008 10:40 am

Will do, Just let me get a little free time.
Altromer521
 
Posts: 3
Joined: Wed Oct 08, 2008 1:12 pm

Re: Practice Stuff

Postby Altromer521 on Sat Oct 18, 2008 11:12 am

Here's a extra credit question from my last test that I got wrong. And I still don't know the answer, because the answer key's not up yet.

Assuming that the user put in valid data, describe what the following code does in detail. The numbers to the left are so you can refer to a line in your description.

Code: Select all
001    int* intPtr = new int;
002    whilte ( intPtr != 0 )
003    {
004        intPtr = new int;
005        cin >> *intPtr;
006        cout << *intPtr + 10;
007        delete intPtr;
008        intPtr = 0;
009    } // end while
010    for ( int i = 0; intPtr == 0; ++i )
011    {
012        intPtr = new int;
013        *intPtr = i;
014        cout << intPtr;
015        intPtr = 0;
016    {  // end for


and here's a project I had to do. Create a calculator that can take in Integers that are larger than the standard 10 characters long and be able to multiply and add them. The input numbers will be non-negative numbers. A hint is to use strings, or arrays (I did it with strings). A good place to look for stuff you can do with strings is the MSDN website. If anyone needs help pm me, and I will try my best to help you. I did this in Visual C++ so my main function would be pretty different but the concepts would be the same.

Lastly If I am suppose to just post my stuff directly into the practice area let me know and I'll move it there. This stuff is harder, but I'll try and find some easier stuff to post later.
Altromer521
 
Posts: 3
Joined: Wed Oct 08, 2008 1:12 pm

Re: Practice Stuff

Postby asib on Mon Oct 20, 2008 7:47 am

Code: Select all
001    int* intPtr = new int;
002    whilte ( intPtr != 0 )
003    {
004        intPtr = new int;
005        cin >> *intPtr;
006        cout << *intPtr + 10;
007        delete intPtr;
008        intPtr = 0;
009    } // end while
010    for ( int i = 0; intPtr == 0; ++i )
011    {
012        intPtr = new int;
013        *intPtr = i;
014        cout << intPtr;
015        intPtr = 0;
016    {  // end for

001 Creates a pointer to an integer on the heap
002 Initializes loop with condition while the pointer is not 0
004 Reassigns the pointer to a new memory location on the heap - old memory location is lost (leaked)
005 Takes a value from the user and puts it into the memory location that the pointer points to
006 Outputs that value plus 10
007 Deletes the int on the heap that the pointer pointed to
008 Assigns the pointer to NULL
009 Exits loop because pointer is no longer not equal to 0
010 Initializes for loop creating variable i and defining it with 0, loop ends if pointer is equal to 0, increments i by 1 BEFORE each iteration
012 Pointer now points to a new int object on the heap
013 Gives the int object the value of i (which is 1)
014 Outputs the address of the pointer
015 Assigns pointer to point to nowhere (NULL) - FOR CONDITION TO END IS NOW TRUE
016 Exits for loop - Condition is true

I think that's right...
asib
 
Posts: 86
Joined: Tue Jul 22, 2008 9:15 pm

Re: Practice Stuff

Postby Doctor Salt on Tue Oct 21, 2008 6:50 pm

Ah, asib beat me to it :P I was gonna post basically the same thing.
I'm a 15 year old kid who has his heart set on Programming, almost as much as Marss++.......

Came here hoping to ask more questions so if you have any free time just say!
Doctor Salt
 
Posts: 147
Joined: Wed Jul 30, 2008 3:32 pm

Re: Practice Stuff

Postby asib on Wed Oct 22, 2008 8:02 pm

Doesn't matter who got it first, just matters if you got it right in my opinion.

And Altromer521, post up the other stuff, I'm interested in some more exercises.
asib
 
Posts: 86
Joined: Tue Jul 22, 2008 9:15 pm


Return to -- Code Practice Submissions --

Who is online

Users browsing this forum: No registered users and 0 guests