d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > So I Need To Learn C++
Add Reply New Topic New Poll
Member
Posts: 8,166
Joined: Jun 3 2007
Gold: 6,025.00
Sep 7 2014 08:49am
My data structures class calls for me teaching myself C++, and i have to write a basic program for monday.
I have some prior java experience. Right now i need to find new IDE to write some code, (text editor and compiler)
If anybody could direct me to any good online C++ learning sources that would be great, also, any tips or bits of advice is greatly appreciated.
Thanks a bunch, and enjoy your day! :thumbsup:
Member
Posts: 1,241
Joined: Jun 25 2011
Gold: Locked
Sep 7 2014 10:19am
For the IDE, Qt creator or codeblocks are good choices
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Sep 7 2014 01:05pm
cplusplus.com
Member
Posts: 8,166
Joined: Jun 3 2007
Gold: 6,025.00
Sep 7 2014 02:08pm
Thanks for the resources! I kept getting an infinite loop when i would try a while loop with
n%10
n/10

but i worked around it with an if else/recursion; So Monday's program should be good to go.
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Sep 7 2014 04:56pm
Quote (Nort @ Sep 7 2014 03:08pm)
Thanks for the resources! I kept getting an infinite loop when i would try a while loop with
n%10
n/10

but i worked around it with an if else/recursion; So Monday's program should be good to go.


I know I always tell people to bother him, but KrzaQ has some good C++ knowledge it would seem. I am not sure how far you are looking to go, but if you post your source here he can probably offer some advice if you are into that kind of thing.

Member
Posts: 8,166
Joined: Jun 3 2007
Gold: 6,025.00
Sep 7 2014 09:50pm
Quote (Eep @ Sep 7 2014 06:56pm)
I know I always tell people to bother him, but KrzaQ has some good C++ knowledge it would seem. I am not sure how far you are looking to go, but if you post your source here he can probably offer some advice if you are into that kind of thing.


Well, It's for a class - SO I'll be going deep enough to pass this, with a minor in CSCI, so I'm looking to learn it well.

Here's the source that i got to work:



#include <iostream>
using namespace std;

void printreverse(int number){

if (number == 0){
cout << ".";
} else {
cout<< (number%10);
printreverse((number/10));
}

}


int main () {

cout << "Please enter an integer to be reversed. \n";
int number;
cin >> number;
cout << "You entered: " << number << ". \n";
cout << "This number reversed is: ";
printreverse(number);


return 0;
}



************************


the while loop that would cause infinite loop was just:

while (number != 0) {
cout<< number%10;
number/10;
}

Still not really sure why that won't work though.

This post was edited by Nort on Sep 7 2014 09:51pm
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Sep 7 2014 09:54pm
Quote (Nort @ Sep 7 2014 11:50pm)
Well, It's for a class - SO I'll be going deep enough to pass this, with a minor in CSCI,  so I'm looking to learn it well.

Here's the source that i got to work:



    #include <iostream>
    using namespace std;

    void printreverse(int number){

        if (number == 0){
            cout << ".";
    } else {
        cout<< (number%10);
      printreverse((number/10));
      }

        }


    int main () {

    cout << "Please enter an integer to be reversed. \n";
    int number;
    cin >> number;
    cout << "You entered: " << number << ". \n";
      cout << "This number reversed is: ";
      printreverse(number);


    return 0;
    }



  ************************


the while loop that would cause infinite loop was just:

while (number != 0) {
cout<< number%10;
number/10;
}

Still not really sure why that won't work though.


number = number/10;
Member
Posts: 8,166
Joined: Jun 3 2007
Gold: 6,025.00
Sep 7 2014 09:55pm
Quote (carteblanche @ Sep 7 2014 11:54pm)
number = number/10;


QQ Good Catch! I do believe that's it.
e: totally it. now i feel silly. :P :bonk:

This post was edited by Nort on Sep 7 2014 10:00pm
Member
Posts: 8,166
Joined: Jun 3 2007
Gold: 6,025.00
Oct 15 2014 09:31pm
So I've hit another roadblock. I need to read in Dog info from a file (create a struct for the dog info) then put each struct into a linked List Node. As it stands now, i can get the info fromt he file and into the structs but when it comes to linking the structs together I can't work my pointers; Here's my Source:


#include <fstream>
#include <iostream>
#include <string>
using namespace std;



struct dogStats
{
string name;
string color;
string breed;
int age;
dogStats(string Name, string Color,
string Breed,int Age): name(Name), color(Color), breed(Breed), age(Age) {}

};

struct Node
{

dogStats dogs;
Node *next;

Node(dogStats dogSpecs, Node *n): dogs(dogSpecs), next(n) {}

};


void swap ()
{



}
int main ()
{
Node *head;
Node *tail;
Node *pointer;


std::ifstream dogFile( "dogs.txt" );
string a, b, c;
int d;
while (dogFile >> a >> b >> c >> d)
{

cout<<a<<endl;

dogStats Temp = dogStats(a,b,c,d);
Node nTemp = Node(Temp,pointer);
cout<< nTemp.dogs.color << " "<< nTemp.dogs.breed << " " << nTemp.dogs.age<<endl;



}


return 0;
}

Member
Posts: 9,803
Joined: Jun 28 2005
Gold: 6.67
Oct 17 2014 02:54am
You should keep a pointer (preferably std::unique_ptr) to the next node, you cannot keep it by value. Most C++ tutorials will have you spewing new and delete all around, but this isn't good C++ since 2011, so please use caution.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll