This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
int myIndex(int numbers[], int size, int element); | |
int main(){ | |
int numbers[] = {1,2,3,4,5,6,7,8,9,0}; | |
int size = sizeof(numbers)/sizeof(numbers[0]); | |
int index; | |
int element; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
void sort(int array[], int size); | |
int main() | |
{ | |
int array[] = {10, 1, 9, 2, 8, 3, 7, 4, 6, 5}; | |
int size = sizeof(array)/sizeof(array[0]); | |
sort(array, size); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
int main(){ | |
const int SIZE = 60; | |
std::string foods[SIZE]; | |
fill(foods, foods + (SIZE/3), "Pizza"); | |
fill(foods+(SIZE/3), foods + (SIZE/2), "Burgers"); | |
fill(foods+(SIZE/2), foods + SIZE, "Hotdog"); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
int main(){ | |
std::string food[10]; | |
int size = sizeof(food)/sizeof(food[0]); | |
std::string temp; | |
for(int i=0;i<size;i++){ | |
std::cout << "Enter the foods you like # or type 'q' if you're done. " << i + 1 << ": "; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
int main(){ | |
// rows . columns | |
std::string colours[][3] = {{"Black","White","Blue"}, | |
{"Orange","Purple","Green"}, | |
{"Yellow", "Red", "Brown"}}; | |
int rows = sizeof(colours)/sizeof(colours[0]); | |
int columns = sizeof(colours[0])/sizeof(colours[0][0]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
int main(){ | |
const double PI = 3.14159; // cant change val later | |
const int LIGHT_SPEED = 299792458; | |
const int WIDTH = 1920; | |
const int HEIGHT = 1080; | |
double radius = 10; | |
double circumference =2 * PI * radius; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
void swap(std::string &x, std::string &y); | |
int main() | |
{ | |
std::string x = "Kool-Aid"; | |
std::string y = "Water"; | |
swap(x, y); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
int main() { | |
// memory address = a location in memory where data is stored | |
// a memory address can accessed with & (address-of operator) | |
std::string name = "BOB"; | |
int age = 21; | |
bool student = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
// Dynamic mem: Memory that is allocated after the | |
// program is already compiled and running. | |
// Use the "new" operator to allocate memory | |
// in the heap rather than the stack | |
/* Useful when we dont know how much memory we will need. | |
Makes our programs more flexible, specially when | |
accepting user input. */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
int factorial(int num); | |
int main(){ | |
std::cout << factorial(5); | |
return 0; | |
} |
OlderNewer