Any good book with c++ exercises

Hi cplusplus community im new to c++ i just started playing around with it a week ago, i also bought the c++ primer book after i saw some warm recommendation about it on this forum and on stackexchange.

My question is if it's any other good book except c++ primer?

i would prefer if it was more focused on exercises because i really lack ideas of what kind of programs i should do when i practice.

Thanks in advance

Just practice writing syntax.. Here are my spark notes I have created for you..Ill write more if you want

1) Declaring Variables.....Just practice declaring different types of variables and out put them to the screen.

1
2
3
4
5
int x = 5;
double y = 3.75;
float z = 8.8;
string str = "This is a string";
cout << x << y << z << endl;  // make sure you use using namespace std and iostream 


2) Practice declaring an Array...This is just a collection of the dataTypes listed above...The analogy that is always used: think about a container..An array is a container that can only hold the same dataTypes.
for example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//Int array
int arrayInts[5] = {1,2,3,4,5};
// or 
string arrayInts2[] = {1,2,3,4,5,6,7,8,,4,3};

//Double Array
double arrayDbles[5] = {4.2, 6.7 };

//String Array
string arrayStr[] = {"One","two","three"};

// How to output an Array

cout << arrayInts[0] << endl; // this prints the first int in the array
cout << arrayInts[1] << endl; // prints second int in array


** You probably should learn for loop, while loop, do while loop, if statement, switch statement here then continue
3) Then practice declaring and calling functions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>

using namespace std;

void myFunction();

int main ()
{
    myFunction();
    
    return 0;
}

void myFunction()
{
    cout << "This is my first function" << endl;
}



4) Passing variables into functions and returning variables
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>

using namespace std;

int myFunction(int Variable_Going_In); // this function takes a 
//variable in and returns a value of type int

int main ()
{
    int in = 10, out;
    
    out = myFunction(in);
    
    cout << out << endl;
    
    return 0;
}

int myFunction(int Variable_Going_In)
{
    int Variable_Going_Out = 9000;
    cout << "This variable is being passed into the function " << Variable_Going_In << endl;
    
    cout << "This variable is being returned or released by this function " << Variable_Going_Out << endl;
    
    return Variable_Going_Out;
}



Last edited on
Ok will do:)

Thanks for the help:D!
Topic archived. No new replies allowed.