-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
131 lines (105 loc) · 4.57 KB
/
main.cpp
File metadata and controls
131 lines (105 loc) · 4.57 KB
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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//
// main.cpp
// learning-cpp
//
// Created by lionel souop on 20/12/2019.
// Copyright © 2019 lionel souop. All rights reserved.
//
#include <iostream>
#include "utils/utils.hpp"
#include "iostream/console_input_output.hpp"
#include "conditionalCompilationAndMacro/conditionalCompilationAndMacros.hpp"
#include "dataTypeAndSize/typesAndSize.hpp"
#include "arraySorting/bubbleSort.hpp"
#include "arraySorting/selectionSort.hpp"
#include "arraySorting/quickSort.hpp"
#include "pointers_array_struct/pointers_array.hpp"
#include "pointers_array_struct/iterators.hpp"
#include "linkedList/linkedList.hpp"
#include "forEachAndReferences/forEachAndReferences.hpp"
//#define CONSOLE_IO
//#define CONDITIONAL_COMPILE_AND_MACRO
//#define TYPE_AND_SIZE
//#define ARRAY_SORTING
//#define POINTERS
//#define LINKED_LIST
#define FOR_EACH_REFERENCES
int main(int argc, const char * argv[]) {
#ifdef CONSOLE_IO
consoleInputOutput();
#endif
#ifdef CONDITIONAL_COMPILE_AND_MACRO
double resultAddition {genericOperator(1, 2, "+")};
std::cout << "The result of the addition is: " << resultAddition << '\n';
//the multiplication is not defined so the part of the code performing the multiplication won't be compiled and the default value will be returned
double resultMultiplication {genericOperator(1, 2, "*")};
std::cout << "The result of the multiplication is: " << resultMultiplication << '\n';
#endif
#ifdef TYPE_AND_SIZE
dataTypesAndSize();
#endif
#ifdef ARRAY_SORTING
int arrayOfInt1[]{45,2,89,5,43,1,7,65,34,2,1,78,5,4,23,4,54};
const int arrayLength {static_cast<int>(sizeof(arrayOfInt1) / sizeof(arrayOfInt1[0]))};
std::cout << "Bubble sort descending mode: \n";
bubbleSort(arrayOfInt1, arrayLength);
printArray(arrayOfInt1, arrayLength);
std::cout << "Selection sort descending mode: \n";
int arrayOfInt2[]{45,2,89,5,43,1,7,65,34,2,1,78,5,4,23,4,54};
selectionSort(arrayOfInt2, arrayLength);
printArray(arrayOfInt2, arrayLength);
std::cout << "Quick sort ascending mode: \n";
int arrayOfInt3[]{45,2,89,5,43,1,7,65,34,2,1,78,5,4,23,4,54};
quickSort(arrayOfInt3, 0, 16);
printArray(arrayOfInt3, 17);
#endif
#ifdef POINTERS
pointers();
pointersAndStruct();
int anArray[]{45,2,89,5,43,1,7,65,34,2,1,78,5,4,23,4,54};
const int threshold{10};
int numberOfElements{countElementBelowThreshold(anArray, sizeof(anArray)/sizeof(anArray[0]), threshold)};
std::cout << "Number of elements lower than the threshold: " << numberOfElements << '\n';
std::string *arrayOfName{pointersAndArray()};
if(arrayOfName){
delete[] arrayOfName;
}
loopOverArrays();
#endif
#ifdef LINKED_LIST
Student* aStudentList{initializeLinkedList("lionel", 18, 29)};
std::cout << "List length after init: " << listLength(aStudentList) << '\n';
appendElement(aStudentList, "brice",18, 30);
std::cout << "List length after append: " << listLength(aStudentList) << '\n';
aStudentList = addInPosition(aStudentList, "souop", 18, 25, 1);
std::cout << "List length after add in position 1: " << listLength(aStudentList) << '\n';
std::cout << "Element in position 1: " << aStudentList->next->name << '\n';
aStudentList = addInPosition(aStudentList, "Ahmed", 18, 25, 0);
std::cout << "List length after add in position 0: " << listLength(aStudentList) << '\n';
std::cout << "Element in position 0: " << aStudentList->name << '\n';
Student* aStudent{getElementAtPosition(aStudentList, 1)};
std::cout << "Get element at position 1: " << aStudent->name << '\n';
delete aStudent;
aStudent = nullptr;
aStudentList = deleteElementAtPosition(aStudentList, 1);
std::cout << "List length after delete element in position 1: " << listLength(aStudentList) << '\n';
aStudent = getElementAtPosition(aStudentList, 1);
std::cout << "Get element at position 1: " << aStudent->name << '\n';
std::cout << "List length: " << listLength(aStudentList) << '\n';
aStudentList = destroyList(aStudentList);
if(!aStudentList)
std::cout << "The list has been successfully destroyed.\n";
else
std::cout << "Error: the list has not been destroyed.\n";
// the following line will throw an exception because the list is not long 100 elements.
//aStudentList = addInPosition(aStudentList, "souop", 18, 25, 100);
// delete
#endif
#ifdef FOR_EACH_REFERENCES
if(doesNameExist())
std::cout << "\nThe name is exists!\n";
else
std::cout << "\nThe name does not exist!\n";
#endif
return 0;
}