Skip to content

Commit 83d8c53

Browse files
committed
Very beginning of C++
0 parents  commit 83d8c53

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# ignore executable files
2+
*.out

001_Helow-World.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include<iostream>
2+
3+
int main() {
4+
std::cout << "First Example Program" << std::endl;
5+
//return 0; //Success status, saying programm worked fine.
6+
return EXIT_SUCCESS; //Optional to return, compiler includes it automatically.
7+
}

002_IO_and_Variables.cpp

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#include<iostream>
2+
#include<string>
3+
#include <math.h>
4+
5+
int main () {
6+
// Integer
7+
int nSum (1); //Initialize
8+
short int snVar1 = 14;
9+
long int lnVar2 = 553;
10+
long long int llnVar3 = -4454;
11+
unsigned int unCount = 56;
12+
unsigned short int usnVar4 = 6435;
13+
unsigned long int ulnVar5 = 73;
14+
unsigned long long int ullnVar6 = 821;
15+
16+
std::cout << "int is: " << nSum << " and size is: " << sizeof(nSum) << \
17+
" Byte" << '\n';
18+
std::cout << "short int is: " << snVar1 << " and size is: " << sizeof(snVar1)\
19+
<< " Byte" << '\n';
20+
std::cout << "long int is: " << lnVar2 << " and size is: " << sizeof(lnVar2)\
21+
<< " Byte" << '\n';
22+
std::cout << "long long int is: " << llnVar3 << " and size is: " \
23+
<< sizeof(llnVar3) << " Byte" << '\n';
24+
std::cout << "unsigned int: " << unCount << " and size is: " << sizeof(unCount)\
25+
<< " Byte" << '\n';
26+
std::cout << "unsigned short int: " << usnVar4 << " and size is: " \
27+
<< sizeof(usnVar4) << " Byte" << '\n';
28+
std::cout << "unsigned long int: " << ulnVar5 << " and size is: " \
29+
<< sizeof(ulnVar5) << " Byte" << '\n';
30+
std::cout << "unsigned long long int: " << ullnVar6 << " and size is: " \
31+
<< sizeof(ullnVar6) << " Byte" << "\n \n";
32+
33+
float fPercentage = 50.66;
34+
double dPrice = 1e-3;
35+
long double ldPI = M_PI;
36+
std::cout << "float is: " << fPercentage << " and size is: " << \
37+
sizeof(fPercentage) << " Byte" << '\n';
38+
std::cout << "double is: " << dPrice << " and size is: " << \
39+
sizeof(dPrice) << " Byte" << '\n';
40+
std::cout << "long double is: " << ldPI << " and size is: " << \
41+
sizeof(ldPI) << " Byte" << "\n \n";
42+
43+
bool bStatus = true;
44+
std::cout << "bool is: " << bStatus << " and size is: " << sizeof(bStatus) <<\
45+
" Byte" << "\n \n";
46+
47+
char cByte = 'P'; // or =u8'a'
48+
char16_t cByte2 = u'R';
49+
char32_t cByte4 = U'I';
50+
std::cout << "char is: " << cByte << " and size is: " << sizeof(cByte) << \
51+
" Byte" << "\n";
52+
std::cout << "char16_t is: " << cByte2 << " and size is: " << sizeof(cByte2) \
53+
<< " Byte" << "\n";
54+
std::cout << "char32_t is: " << cByte4 << " and size is: " << sizeof(cByte4) \
55+
<< " Byte" << "\n";
56+
57+
58+
std::string sLine ;
59+
sLine = "This is a String variable";
60+
61+
std::cout << "Enter Input integer: " << '\n';
62+
std::cin >>unCount;
63+
if(!std::cin.good()){
64+
std::cerr << "Invalid input." << "\n";
65+
}
66+
else {
67+
nSum += unCount; //https://stackoverflow.com/a/30036580/10451749
68+
std::cout << "Sum is: " << nSum << '\n';
69+
}
70+
71+
std::cout << "Enter String Message: " << '\n';
72+
// std::cin >> sLine;
73+
std::cin.ignore(); //ignore '\n' character in the stream left by previous read
74+
getline (std::cin, sLine);
75+
std::cout << sLine << '\n';
76+
return EXIT_SUCCESS;
77+
78+
}

0 commit comments

Comments
 (0)