Sie sind auf Seite 1von 33

This video is to show you how to create a simple Hello World!

Program in C++.
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

// Use this library to be able to do cout and cin.


#include <iostream>
// Use this so you can add lines in the code. Otherwise, you'll need to do
std:: to every line.
using namespace std;
// Everything inside main will be excuted when the program is compiled.
void main()
{
//
//
//
//
//
//

This will display:


Hello World!
How are you
Press any key to continue . . .

cout << "Hello World!" << endl << endl << "How are you?\n\n";
// This line will pause your program so it waits for you to press
any key and it will display:
// Press any key to continue . . .
system("pause");
}

This video is an introduction to variables and console input.


Example of variables and initialization:

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
30
31
32
33
34
35
36
37
38
39
40

#include <iostream>
#include <string>
using namespace std;
void main()
{
// Below are variables and how to use them.
// Types are int, double, float, char and string.
// Initilization is important and goes after the =
// Reserved words are not to be used anywhere else.
int Num1 = 0, Num2 = 0, Num3 = 0;
double DNum1 = 0.0, DNum2 = 0.0 , DNum3 = 0.0;
float FNum1 = 0.0f, FNum2 = 0.00f, FNum3 = 0.00f;
char Letter1 = ' ', Letter2 = ' ', Letter3 = ' ';
string Word1 = "", Word2 = "", Word3 = "";
// This line will ask the user to input a number.
cout << "Please input Num1" << endl;
// This line will ask for an input. It will not display anything
// But it will wait for an input.
cin >> Num1;
cout << "Please input Num2\n";
cin >> Num2;
cout << "Please input Num3\n";
cin >> Num3;
// This outputs everything.
cout << Num1 << " " << Num2 << " " << Num3 << endl;
system("pause");
}

This tutorial introduces you to if statements and switch statements


and how to use them with all kind of variables.
If statement example:

*Must use == to check if condition is the same.


*Must start with if and the rest is optional.
*Else does not have a condition.
*For AND use &&. For OR use ||
*Brackets are not necessary for one line, but its good practice.
*The format is if, optional number of else ifs then at the end if else.

Code for If statements:


1
2
3
4
5
6
7
8
9
10
11

#include <iostream>
#include <string>
using namespace std;
void main()
{
// Variables and initilization.
int Num1 = 0, Num2 = 0, Num3 = 0;
double DNum1 = 0.0, DNum2 = 0.0 , DNum3 = 0.0;

12
float FNum1 = 0.0f, FNum2 = 0.00f, FNum3 = 0.00f;
13
14
char Letter1 = ' ', Letter2 = ' ', Letter3 = ' ';
15
string Word1 = "", Word2 = "", Word3 = "";
16
17
// Asking for input.
18
19
cout << "Please input Num1" << endl;
20
cin >> Num1;
21
22
cout << "Please input Num2\n";
23
cin >> Num2;
24
25
cout << "Please input Num3\n";
26
cin >> Num3;
27
28
// Example of if's.
29
30
// We HAVE to start with an if, then else if then else. You don't
31 have to have an else.
32
// You have to restate the Num1 each time you compare it.
33
// Example of and which is &&
34
35
if (Num1 == Num2 && Num1 == Num3)
36
{
37
cout << "Number 1 is equal to all other numbers" << endl;
38
}
39
40
// Else if is the same as if.
41
// Example of or which is ||
42
43
else if (Num1 == Num2 || Num1 == Num3)
44
{
45
46
// You have to start with if again since you are inside a
47 new bracet.
48
49
if (Num1 == Num2)
50
{
51
cout << "Number 1 is equal to Number 2" << endl;
52
}
53
54
else if (Num1 == Num3)
55
{
56
cout << "Number 1 is equal to Number 3" << endl;
57
}
58
}
59
60
// Example of else.
61
// It does not ge a condition.
62
63
else
64
{
65
cout << "Number 1 is not equal to any other numbers" <<
66 endl;
67
}

cout << Num1 << " " << Num2 << " " << Num3 << endl;

68
69
}

system("pause");

Switch statement example:


*Must use break; to stop the code from running until the end.

String positions example:

Code for Switch statements:


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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

#include <iostream>
#include <string>
using namespace std;
void main()
{
// Variables.
int Num1 = 0, Num2 = 0, Num3 = 0;
double DNum1 = 0.0, DNum2 = 0.0 , DNum3 = 0.0;
float FNum1 = 0.0f, FNum2 = 0.00f, FNum3 = 0.00f;
char Letter1 = ' ', Letter2 = ' ', Letter3 = ' ';
string Word1 = "", Word2 = "", Word3 = "";
// Inputting an int in Num1.
cout << "Please input Num1" << endl;
cin >> Num1;
// Example of switch statement with numbers.
switch (Num1)
{
// In case it is a 1.
case 1:
cout << "You've entered number 1" << endl;
// You have to use breaks so the code stops here and won't

go on.

break;
// In case it is a 2.
case 2:
cout << "You've entered number 2" << endl;
break;
case 3:

cout << "You've entered number 3" << endl;


break;
// In case its between 5 - 10.

case 5: case 6: case 7: case 8: case 9: case 10:


cout << "You've entered a number between 5 - 10" << endl;
break;
// Any other number is caught here.
// Default is not necessary.
// Default does not always need a break because the bracet

55 will stop it.


56
57
default:
58
cout << "You've entered the wrong number" << endl;
59
}
60
61
// Inputting a char.
62
63
cout << "Please input letter 1" << endl;
64
cin >> Letter1;
65
66
// Example of switch statement with chars.
67
// Case sensative.
68
69
switch (Letter1)
70
{
71
72
// In case it is an A
73
74
case 'A':
75
cout << "You've entered letter A" << endl;
76
break;
77
case 'B':
78
cout << "You've entered letter B" << endl;
79
break;
80
case 'C':
81
cout << "You've entered letter C" << endl;
82
break;
83
84
// In case it is between E - G
85
86
case 'E': case 'F': case 'G':
87
cout << "You've entered the letter between E - G" << endl;
88
break;
89
90
// All other letters go here.
91
92
default:
93
cout << "You've entered the wrong letter" << endl;
94
}
95
96
// Inputting a string.
97
98
cout << "Please input Word 1" << endl;
99
cin >> Word1;
100
101
// Example of switch statement with strings.
102
// Switch only works with numbers and chars so we have to use
103 the .at
104
// function so we treat it as a char.
105
106
switch (Word1.at(1))
107
{
108
109
// In case it is an A.
110

case 'A':
cout << "You've entered letter A" << endl;
break;
case 'B':
cout << "You've entered letter B" << endl;
break;
case 'C':
cout << "You've entered letter C" << endl;
break;

111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135

// In case it is between E - G
case 'E': case 'F': case 'G':
cout << "You've entered the letter between E - G" << endl;
break;
// Other letters go here.
default:
cout << "You've entered the wrong letter" << endl;
}
// Normal output. Not needed.
cout << Num1 << " " << Num2 << " " << Num3 << endl;
system("pause");
}

An intro to for, while, and do while loops in C++.


For loop example:
*Used if we know how many times we are looping.
*May not execute during a code.

While loop example:


*Used if we dont know how many times we are looping.
*May not execute during a code.

Do while loop example:


*Used if we need to check how many times do we need to loop.
*Will execute at least once.

Code:
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

#include <iostream>
using namespace std;
void main()
{
// Initialization.
int Num1 = 0, Total = 0, i = 0;
// Processing.
// Example of do while loop.
// Goes at least once then checks the condition.
do
{
cout << "Please input a number: ";
cin >> Num1;
Total += Num1;
cout << endl;
// This is the counter;

i++;
27
28
// Condition right here.
29
30
} while(i < 5);
31
32
// Example of while loop.
33
34
// Used if we don't know how long we are looping.
35
// May not excute at all throuout the code if the condition is
36
false.
37
// Condition is while i is less than 5.
38
39
while (i < 5)
40
{
41
cout << "Please input a number: ";
42
cin >> Num1;
43
44
Total = Total + Num1;
45
cout << endl;
46
47
// Counter is right in here.
48
49
i++;
50
}
51
52
// Example of for loop.
53
54
// Start with where do we start from?
55
// How many do we go?
56
// Counter.
57
58
// (Start from; How many; counter)
59
60
for (int i = 0; i < 5; i++)
61
{
62
cout << "Please input a number: ";
63
cin >> Num1;
64
65
// These two codes are the same.
66
67
// Total = Total + Num1;
68
Total += Num1;
69
70
cout << endl;
71
}
72
73
// Output.
74
75
cout << "The Total is " << Total << endl;
76
77
system("pause");
78
}

This tutorial will show you how to use files for input and output.

Code:
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

#include <iostream>
// Library for file input and output.
// Just like iostream, it is a stream.
#include <fstream>
using namespace std;
void main()
{
// Variable.
float Num1 = 0.0f, Num2 = 0.0f, Total = 0.0f;
char Oper = ' ';
// Making the file input and file output.
// They are just like variables.
ifstream fin;
ofstream fout;
// The open function opens files.
// fin will not create the file for you, you have to make
// it and it is very case sensative.
fin.open("Input.txt");
// The output file will be created for you.
fout.open("Output.txt");
// This if is to check if the file was opened or not.
if (!fin)
{
cout << "File is not opening right." << endl;
system("pause");
exit(0);
}
// Processing.
// Input before we go into the loop.
// The input will take a number, number, then a char.
//
//
//
//
//
//

File will look like this:


5 3 +
4 3.5 And so on.

fin >> Num1 >> Num2 >> Oper;

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97 }

// While it isn't the end of the file.


// eof is for end of file and ! is for not.
while (!fin.eof())
{
switch (Oper)
{
case '+':
Total =
break;
case '-':
Total =
break;
case '*':
Total =
break;
case '/':
Total =
break;
default:
fout <<

Num1 + Num2;
Num1 - Num2;
Num1 * Num2;
Num1 / Num2;
"The operator used is wrong." << endl;

// This reinitialization is so that we don't


// output the last number inside Total from
// the previous calculator of the last line.
}

Total = 0.0f;

// Output.
fout << "Total is " << Total << endl;
// Input at the end of processing inside the loop
// to check for end of file correctly.
// Otherwise, we'll run the last line twice.
fin >> Num1 >> Num2 >> Oper;
}
system("pause");

Content of Input.txt
5 5 +
9 3.5 8 6 *
50 23 /
9 7 &

This tutorial explains how to use functions in C++.

Void function example:


*Void functions dont have to do return.
*Void functions cant be displayed as cout << function();

Return function example:


*Return type functions are anything other than void (string, int, double, char, float)
*Return type functions have to do return (Variable/Output similar to the function type)
*You can do cout << function(); with return type function or variable = function();

Code:

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
// This is a global variable which can be used anywhere in the code.
string GlobalWord = "Hello";
// These are prototypes, they come before main.
// Reason for this is because the compiler is like a highway, if it
doesn't see
// that there is a function before it, it won't see it.
// To let it know that there is infact something behind it, we do
prototypes.
// You just copy the first line of a function and paste it here with a
semicolon.
string StrFunc1();
void VoidFunc1(string WordFromMain);
void SimpleCalc(char &Choice, float &Total, float &Num1, float &Num2,
ifstream &fin);
void main()
{
char Choice = ' ';
float Total = 0.0f, Num1 = 0.0f, Num2 = 0.0f;
ifstream fin;
fin.open("Input.txt");
fin >> Num1 >> Num2 >> Choice;
while (!fin.eof())
{
// This is how you call a function.
// The inputs have to match the parameters of the code.
SimpleCalc(Choice, Total, Num1, Num2, fin);
cout << Total << " " << GlobalWord << endl;
}
// VoidFunc1(Word);
/*cout << StrFunc1() << endl;*/
}

system("pause");

// This is the Calc function.


// It has 5 parameters and the & sign is to pass things back to main.
// We have to match the perameters inside main if we want to use it.

57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112

// To pass the file input you redefine it here.


void SimpleCalc(char &Choice, float &Total, float &Num1, float &Num2,
ifstream &fin)
{
switch (Choice)
{
case '+':
Total = Num1 + Num2;
break;
case '-':
Total = Num1 - Num2;
break;
case '*':
Total = Num1 * Num2;
break;
case '/':
Total = Num1 / Num2;
break;
default:
cout << "You've chosen the wrong opererator" << endl;
}
// This is to show you that you can use global variables inside
functions.
cout << GlobalWord << endl;
fin >> Num1 >> Num2 >> Choice;
}
// This is a return type function.
// Return type functions are:
// string, int, double, float, char.
string StrFunc1()
{
string Word = "";
cout << "Please input a word: ";
cin >> Word;
// You have to do return because its a return type function.
}

return Word;

// This is a void function.


// It has one parameter.
void VoidFunc1(string WordFromMain)
{
string Word = "";

cout << "Please input a word: ";


cin >> Word;
113
114

cout << Word << " " << WordFromMain << endl;
// No need for a return because its a void function.
}

Content of Input.txt
50 40 *
3 6 /
5 8 9 6 +
4 8 "

This is an intro to enums and how to use them inside


main/functions. The purpose of them is to use them in conditional
processing rather than just displaying the output right away

Enum initialization example:


*Enum initialization doesnt need an = only brackets such as { and }
*To pass enums you call its variable name (From when you made it) then give it a variable name.

Enum calling example:

Code:
1
2
3

#include <iostream>
using namespace std;

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

//
//
//
//

Here you make enum.


You call it as if you call string, int, double, etc...
and give it a variable name. To initialize it you don't
need to do equals, just open brackets, initialize and close brackets.

// You also need to position it here, right under using namespace std;
// so that every function can see it.
enum NumberChoice {ONE, TWO, THREE, ERROR};
// Function prototypes.
void processNum(int Num, NumberChoice &FunctionChoice);
void displayNum(NumberChoice Choice);
void main()
{
int Num = 0;
NumberChoice Choice = ERROR;
// Input from the user.
cout << "Please input a number between 1-3: ";
cin >> Num;
// This function checks what the Num is.
processNum(Num, Choice);
// This function displays what Num did the user display.
displayNum(Choice);
}

system("pause");

// This function checks what the num is.


// To pass enum to a function, use its name from the top and give
// a variable name to it. To pass it back use the & sign before
// the variable name.
void processNum(int Num, NumberChoice &FunctionChoice)
{
// See what Num is.
switch (Num)
{
case 1:
// Set the enum to ONE if the user inputs 1.
FunctionChoice = ONE;
break;

60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104

case 2:

case 3:

FunctionChoice = TWO;
break;
FunctionChoice = THREE;
break;

default:
FunctionChoice = ERROR;
}
}

cout << endl;

// This function displays what Num did the user display.


void displayNum(NumberChoice Choice)
{
// Check what the enum is.
switch (Choice)
{
// Display "You've entered number 1." if the enum
// is ONE which is set by processNum.
case ONE:
cout << "You've entered number 1.";
break;
case TWO:
cout << "You've entered number 2.";
break;
case THREE:
cout << "You've entered number 3.";
break;
default:
cout << "You've entered a number other than 1-3.";
}
}

cout << endl;

This tutorial introduces you on how you can use arrays rather than
single variables. Its useful when dealing with files and a large
amount of data.

Array initializing example:


*To give a size, put a number or a const inside the brackets [5]
*To make an array without a size dont put anything in the brackets. []

Inside the array example:

Array calling example:

*When passing to a function, no need to include the brackets, just the variable name.
*When using inside a function, you need to use the brackets but without a size, the size will be
passed through main.

Code:
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

#include <iostream>
#include <string>
#include <fstream>
using namespace std;
// Here we use a constant for the array size so
// we don't have to keep chaning the sizes all the time.
const int MAX_ARRAY = 5;
// Function prototypes.
void fillArray(int Num[], string Word[]);
void displayArray(int Num[], string Word[]);
void fillCharArray(ifstream &fin, char Letters[], int &size);
void displayCharArray(char Letters[], int size);
void main()
{
ifstream fin("Input.txt");
// Defining int, char and string arrays.
// To give a size, do [size]
// If you don't know the size, do []
// To fill all of them at once you can do:

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84

// {0} or {""} or {' '} or {0.0} depending on the type.


int Num[MAX_ARRAY] = {0}, size = 0;
string Word[MAX_ARRAY] = {""};
char Letters[] = {' '};
// Passing arrays does not need a bracket, just the variable name.
fillCharArray(fin, Letters, size);
displayCharArray(Letters, size);
cout << endl;
fillArray(Num, Word);
displayArray(Num, Word);
system("pause");
}
// This function fills the array, you need to name it as
// if its an array with the [] and no size will be passed
// as it will be passed when you do it in main.
void fillArray(int Num[], string Word[])
{
// For loop to fill the arrays.

for (int x = 0; x < MAX_ARRAY; x++)


{
Num[x] = x;
Word[x] = "IndieDevelopment.";
}

// Display the array.


void displayArray(int Num[], string Word[])
{
for (int i = 0; i < MAX_ARRAY; i++)
{
cout << Num[i] << " " << Word[i] << endl;
}
}
// Filling an array of chars using a file.
void fillCharArray(ifstream &fin, char Letters[], int &size)
{
fin >> Letters[size];
while (!fin.eof())
{
size++;
fin >> Letters[size];

85
86
87
88
89
90
91
92
93
94
95
96

}
}
// Displaying the array of chars.
void displayCharArray(char Letters[], int size)
{
for (int i = 0; i < size; i++)
{
cout << Letters[i];
}
}

Content of Input.txt
IndieDevelopment.co

This intro tutorial will show you how you can use structures to
better compact your code.

Example of Structure:
*Can not initialize variables inside it.
*Needs a semicolon after the last curly bracket.

Example of accessing structures.


*Needs a period (.) to access the information in it.

Header File:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

// Libraries.
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
// This is the structor and person is the variable name.
struct person
{
// Structor variables.
string name;
float salary;
}; // Semicolin is needed here.

Main File:
1
2
3
4
5
6

// Including the header file.


#include "Header.h"
void main()
{

// Making the new structors in main using the structor from


Header.h file.
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

person employees[5], students[5];


// Making the names and salary to fill the structors.
string names[5] = {"John Doe", "John Jackson", "Jill Robinson",
"Jackson Jill", "Zee Jackson"};
float salary[5] = {15000.10, 25000.10, 35000.10, 45000.10,
55000.10};
// Filling the employees structor.
for (int i = 0; i < 5; i++)
{
// Filling the name and salary inside the employees
structor.
employees[i].name = names[i];
employees[i].salary = salary[i];
// Displaying the structor.
cout << employees[i].name << " " << employees[i].salary <<

endl;
}

cout << endl;


// Filling the students structor and displaying it.
for (int i = 0; i < 5; i++)
{
students[i].name = names[i];
students[i].salary = 0.0f;
cout << students[i].name << " " << students[i].salary <<
endl;

}
system("pause");

This intro tutorial will show you how you can use classes which is
the most up to date way of programming and will help you use less
code and less variables and produce faster programs.
Class Example:
*Put into a Header file.
*Must use a semicolin after the last squirrely bracket.
*Classes need names.
*Items inside the private area can not be used outside the class unless we access the class first.
*Items used in the public area will have the ability to use the private items and will be used for
functions.
*Constructures run automatically once you call the class in main.

Class Functions Example:

*Put into a CPP file.


*Functions MUST start with the class variable name then ::

Class in Main Example:


*Use the constructor you want right when you make main.
*Use the period to access the functions from the class.

CardHeader.h File:
1
2
3
4
5
6
7
8
9
10
11

#include <iostream>
using namespace std;
// The class is here. Card is the class name.
class Card
{
// The private section is set by default but also can be
// written as private:

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

// Variables usually go here.


private:
int face;
char suit;
// The public section has to be set by user by writing
// public:
// Functions usually go here.
public:
// Constructors.
Card(); // Default Constructor.
Card(int, char); // Custom Constructor.
// Functions.
void display(); // Displays the variables.
// Setters.
// Sets the private variables in main.
void setFace(int);
void setSuit(char s);
// Getters.
// Displays/Gets the private variables in main.
int getFace();
char getSuit();
};

CardHeaderDriver.h File:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

// Including the CardHeader.h file so we can use the functions


// of the class.
#include "CardHeader.h"
// Writing the display function from the Card class.
void Card::display()
{
cout << suit << " ";
switch(face)
{
case 11: cout << "J";
break;

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

case 12: cout << "Q";


break;
case 13: cout << "K";
break;
case 1: cout << "A";
break;
default: cout << face;
}
}

cout << endl;

// Writing the default constructor.


// It sets the variables once you make a new Card class
// in main.
Card::Card()
{
// Variables become avaliable to you since you're using
// the class when you do Card::

face = 2;
suit = 'H';

// Writing the custom constructor.


// It sets the variables once you make a new Card class
// in main.
Card::Card(int face, char s)
{
suit = s;
this->face = face;
}
// Setter functions.
// They will set the private variables to whatever is passed to them.
void Card::setFace(int f)
{
face = f;
}
void Card::setSuit(char s)
{
suit = s;
}
// Getter functions.
// They will return the private variables.
// You can also use a void function and do cout instead.

72
73
74
75
76
77
78
79
80
81

int Card::getFace()
{
return face;
}
char Card::getSuit()
{
return suit;
}

Main File:
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43

// Including the CarHeader.h file.


// This is to look at the libraries and functions for the header file.
#include "CardHeader.h"
// Simple main.
void main()
{
// Array of class.
Card hands[5];
// Setting the face and the suit
hands[0].setFace(1);
hands[0].setSuit('H');
// Displaying all the hands of the Card class.
for (int x = 0; x < 5; x++)
{
hands[x].display();
}
// Making a variable of Card class (hand) and using the
// custom constructor.
Card hand(11, 'S');
// Using the setFace function to set the int variable
// face inside Card class.
hand.setFace(13);
// Using the display function to display the face and the
// suit. Inside the CardHeaderDriver.cpp file.
hand.display();
// Using the setSuit function to set the char variable
// suit inside Card class.

44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62 }

hand.setSuit('H');
hand.setFace(1);
// Using display again.
hand.display();
hand.setFace(1);
// Using the getters to display the face and the suit with the
// cout.
cout << "This is the suit " << hand.getSuit()
<< " This is the face " << hand.getFace()
<< endl;
system("pause");

Das könnte Ihnen auch gefallen