Compare commits

...

No commits in common. "d4f52f28420f2d32d1eb4e003739ea9c079e76a7" and "0746a9affd19289f56debd5f768f6c4ed96e89ec" have entirely different histories.

20 changed files with 196 additions and 2 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.vscode*

View File

@ -1,2 +0,0 @@
# basics

BIN
array Executable file

Binary file not shown.

14
array.cpp Normal file
View File

@ -0,0 +1,14 @@
#include <iostream>
using namespace std;
int main() {
string alphabets[] = {"a", "b", "c", "d"};
int primeNumbers[4];
primeNumbers[0] = 2;
primeNumbers[1] = 3;
primeNumbers[2] = 5;
primeNumbers[3] = 7;
}

BIN
class Executable file

Binary file not shown.

57
class.cpp Normal file
View File

@ -0,0 +1,57 @@
#include <iostream>
#include <vector>
using namespace std;
class GameCharacter {
public:
int maxHealth, currentHealth, attack, defense;
GameCharacter(int, int, int);
void takeDamage(int);
};
GameCharacter::GameCharacter(int h, int a, int d) {
maxHealth = h;
currentHealth = h;
attack = a;
defense = d;
}
void GameCharacter::takeDamage(int damage) {
damage = attack - defense;
if (defense < 0) {
damage = 0;
}
currentHealth -= damage;
}
class Player: public GameCharacter {
public:
string name;
vector<string> inventory;
Player(string, int, int, int);
void addItem(string);
};
Player::Player(string n, int h, int a, int d):GameCharacter(h, a, d) {
name = n;
}
void Player::addItem(string item) {
inventory.push_back(item);
}
int main() {
GameCharacter character = GameCharacter(100, 20, 10);
cout << "Health before taking damage: " << character.currentHealth << "\n";
character.takeDamage(5);
cout << "Health after taking damage: " << character.currentHealth << "\n\n";
Player p = Player("Kishan", 120, 30, 10);
p.addItem("boots");
cout << "Length of the inventory of " << p.name << ": " << p.inventory.size() << "\n";
}

BIN
functions Executable file

Binary file not shown.

18
functions.cpp Normal file
View File

@ -0,0 +1,18 @@
#include <iostream>
using namespace std;
int takeDamage(int attack, int defense) {
int damage = attack - defense;
if (damage < 0) {
damage = 0;
}
return damage;
}
int main() {
int damage = takeDamage(9, 5);
cout << damage;
}

BIN
hello_world Executable file

Binary file not shown.

6
hello_world.cpp Normal file
View File

@ -0,0 +1,6 @@
#include <iostream>
// This is a comment
int main() {
std::cout << "Hello World!";
}

BIN
if_else Executable file

Binary file not shown.

19
if_else.cpp Normal file
View File

@ -0,0 +1,19 @@
#include <iostream>
using namespace std;
int main() {
int health;
int maxHealth = 100;
cout << "Input current health: ";
cin >> health;
if (health <= maxHealth / 4) {
cout << "Health low!";
} else if (health <= maxHealth / 2) {
cout << "Be careful!";
} else {
cout << "Going great!";
}
}

BIN
input_output Executable file

Binary file not shown.

16
input_output.cpp Normal file
View File

@ -0,0 +1,16 @@
#include <iostream>
using namespace std;
int main() {
string name;
string age;
cout << "What's your name?";
cin >> name;
cout << "How old are you?";
cin >> age;
cout << "Hi, my name is " << name << ", and I am " << age << " years old.";
}

BIN
vars_pointers Executable file

Binary file not shown.

21
vars_pointers.cpp Normal file
View File

@ -0,0 +1,21 @@
#include <iostream>
using namespace std;
int main() {
float myFloat;
myFloat = 25 / 2;
bool isGameOver = true;
char character = '#';
character = '!';
int counter = 1;
int *count;
count = &counter;
cout << "Value: " << *count << "\n";
cout << "Memory Address: " << count;
}

BIN
vector Executable file

Binary file not shown.

25
vector.cpp Normal file
View File

@ -0,0 +1,25 @@
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<string> inventory;
inventory.push_back("sword");
inventory.push_back("shield");
inventory.push_back("boots");
inventory.pop_back();
string front = inventory.front();
cout << "First element in inventory: " << front << "\n";
string back = inventory.back();
cout << "Last element in inventory: " << back << "\n";
cout << "\n";
for (int i = 0; i < inventory.size(); i++) {
cout << i << ": " << inventory[i] << "\n";
}
}

BIN
while Executable file

Binary file not shown.

19
while.cpp Normal file
View File

@ -0,0 +1,19 @@
#include <iostream>
using namespace std;
int main() {
int xPos = 0;
int endPos = 10;
while (true) {
xPos++;
cout << xPos << '\n';
if (xPos >= endPos) {
break;
}
}
cout << "Game Over! \n";
}