initial
This commit is contained in:
24
charP.cpp
Normal file
24
charP.cpp
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int countX (const char *p, const char *x) {
|
||||||
|
if (p==nullptr) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
for (; *p != 0; p++) {
|
||||||
|
if (*p == *x) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main (void) {
|
||||||
|
cout << countX("Haaay, Koray", "a") << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
31
classTest.cpp
Normal file
31
classTest.cpp
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
class Max {
|
||||||
|
private:
|
||||||
|
int mInt1, mInt2;
|
||||||
|
|
||||||
|
public:
|
||||||
|
int int1, int2;
|
||||||
|
Max(int int1, int int2) :
|
||||||
|
mInt1 {int1}, mInt2 {int2}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int bigger() {
|
||||||
|
if (int2 >= int1) {
|
||||||
|
return int2;
|
||||||
|
} else {
|
||||||
|
return int1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
int x = 5, y = 7;
|
||||||
|
|
||||||
|
Max max{x, y};
|
||||||
|
|
||||||
|
std::cout << max.bigger() << std::endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
20
funcT.cpp
Normal file
20
funcT.cpp
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int fun1 (int);
|
||||||
|
int fun2 (int);
|
||||||
|
|
||||||
|
int main (void) {
|
||||||
|
cout << fun1(4) + fun2(3) << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int fun1 (int i) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
int fun2 (int j) {
|
||||||
|
return j;
|
||||||
|
}
|
||||||
9
hello.cpp
Normal file
9
hello.cpp
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#include <iostream>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main (void) {
|
||||||
|
|
||||||
|
cout << "Hello world!" << endl;
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
8
importT.cpp
Normal file
8
importT.cpp
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import std;
|
||||||
|
|
||||||
|
|
||||||
|
int main (void) {
|
||||||
|
std::cout << "Hello World!";
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
13
limits.cpp
Normal file
13
limits.cpp
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <climits>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main (void) {
|
||||||
|
|
||||||
|
cout << INT_MAX << endl;
|
||||||
|
cout << INT_MIN << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
19
stringConcatenation.cpp
Normal file
19
stringConcatenation.cpp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
using namespace std;
|
||||||
|
// return a string that contains n As
|
||||||
|
// In Java this code takes forever
|
||||||
|
string makeLongString( int n )
|
||||||
|
{
|
||||||
|
string result = "";
|
||||||
|
for( int i = 0; i < n; i++ )
|
||||||
|
result += "A";
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
int main( )
|
||||||
|
{
|
||||||
|
string manyAs = makeLongString( 250000 );
|
||||||
|
cout << "Short string is " << makeLongString( 20 ) << endl;
|
||||||
|
cout << "Length is " << manyAs.length( ) << endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
21
sumV.cpp
Normal file
21
sumV.cpp
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int vectorSum(const vector<int>& v) {
|
||||||
|
int result = 0;
|
||||||
|
for(const int i : v) {
|
||||||
|
result += i;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main (void) {
|
||||||
|
|
||||||
|
vector nums {2, 4, 6, 8, 10};
|
||||||
|
cout << vectorSum(nums) << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
20
swap2.cpp
Normal file
20
swap2.cpp
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void swap2 (int &val1, int &val2) {
|
||||||
|
int temp = val1;
|
||||||
|
val1 = val2;
|
||||||
|
val2 = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main (void) {
|
||||||
|
int x = 1;
|
||||||
|
int y = 3;
|
||||||
|
|
||||||
|
swap2(x, y);
|
||||||
|
|
||||||
|
cout << x << y << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
8
testParenth.cpp
Normal file
8
testParenth.cpp
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#include <iostream>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main (void) {
|
||||||
|
int num {6};
|
||||||
|
cout << num << endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
18
vectorTest.cpp
Normal file
18
vectorTest.cpp
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main (void) {
|
||||||
|
vector<int> squares;
|
||||||
|
|
||||||
|
for (int i = 0; i < 100; i++) {
|
||||||
|
squares.push_back(i * i);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int j = 0; j < squares.size(); j++) {
|
||||||
|
cout << j << "squared is: " << squares[j] << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user