forked from faranakR/full-cpp-tutorial-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchapter_33_best_practices.cpp
More file actions
98 lines (78 loc) · 3 KB
/
chapter_33_best_practices.cpp
File metadata and controls
98 lines (78 loc) · 3 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
/*=============================================================================
* CHAPTER 33: BEST PRACTICES
* =============================================================================
*
* C++ Development Course - Consolidated Examples
* Original Author: Faranak Rajabi
*
* This file contains 4 code example(s) from Chapter 33.
*
* USAGE:
* - Review each example section
* - Uncomment the code you want to test
* - Compile: g++ -std=c++17 -Wall thisfile.cpp -o program
* - Run: ./program
*
* NOTE:
* Some examples are code snippets designed to illustrate specific
* concepts and may need additional context to compile.
*
=============================================================================*/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
// ============================================================================
// EXAMPLE 1: Code Example
// ============================================================================
/*
if ( pos != nums . end () ) {
std :: cout << " Found number > 4: " << * pos << ’\ n ’;
}
*/
// ============================================================================
// EXAMPLE 2: Rule 4: Overloading vs defaults
// ============================================================================
/*
}
void useDefault ( int size = get DefaultS ize () ) {
std :: cout << " Size is : " << size << ’\ n ’;
24 }
// Rule 4: Overloading vs defaults
void ambiguous ( int x ) {
std :: cout << " One parameter : " << x << ’\ n ’;
29 }
void ambiguous ( int x , int y = 20) {
std :: cout << " Two parameters : " << x << " , " << y << ’\ n ’;
33 }
*/
// ============================================================================
// EXAMPLE 3: Example 1: Coordinate conversion
// ============================================================================
int main () {
// Example 1: Coordinate conversion
P ol ar Co o rd in at e polar {5.0 , M_PI / 4}; // radius =5 , angle =45 degrees
Point cartesian = p o l a r T o C a r t e s i a n ( polar ) ;
std :: cout << " Cartesian : ( " << cartesian . x << " , " << cartesian . y << " ) \ n " ;
// Example 2: Multiple return values
Divi sionResu lt result = divide (17 , 5) ;
std :: cout << " 17 / 5 = " << result . quotient
<< " remainder " << result . remainder << ’\ n ’;
// ============================================================================
// EXAMPLE 4: Output :
// ============================================================================
int main () {
std :: cout << " Creating TextBox with default constructor :\ n " ;
TextBox box1 ;
// Output :
// Widget default constructor
// TextBox default constructor
// ============================================================================
// MAIN FUNCTION
// ============================================================================
// Uncomment the examples above and add your test code here
int main() {
std::cout << "Chapter 33: Best Practices" << std::endl;
// Your test code here
return 0;
}