Skip to content

Instantly share code, notes, and snippets.

@krysseltillada
krysseltillada / Game.h
Created May 14, 2015 20:58
Tic tac toe game
#define GAME_H
#ifdef GAME_H
#include <iostream>
#include <cstdlib>
#include <iomanip>
const int MAXROW = 3;
const int MAXCOL = 3;
@krysseltillada
krysseltillada / sort.cpp
Created May 18, 2015 22:15
sorting ascending to descending(bubble sort)
#include <iostream>
int main()
{
const int MAXVAL = 5;
int num[MAXVAL] = {22 , 1, 33, 9, 10};
int temp = 0;
for(int i = 0; i < MAXVAL; i++) { /// sorts in descending order
for(int n = i + 1; n < MAXVAL; n++) {
@krysseltillada
krysseltillada / str_upp.cpp
Created May 18, 2015 22:57
uppercasing each words(each strings) in a vector
#include <iostream> /// std::cout // std::endl
#include <vector> /// std::vector
#include <cctype> /// toupper();
int main()
{
std::vector<std::string> words; /// initialized a empty vector of string
std::string temp_word; /// stores an temporary input
while(std::cin >> temp_word)
@krysseltillada
krysseltillada / vec_it.cpp
Created May 19, 2015 15:04
accessing vectors using iterators
#include <iostream>
#include <vector>
int main()
{
std::vector<int> v1 = {1};
auto it1 = v1.begin();
std::cout << *it1 << std::endl;
std::vector<int> v2(10, 2);
@krysseltillada
krysseltillada / vec_str_upp_it.cpp
Created May 19, 2015 15:23
uppercasing vector of strings using iterators
#include <iostream>
#include <string>
#include <vector>
int main()
{
std::vector<std::string> vec_str = {"helllllllllllllo"};
for(auto it = vec_str.begin(); it != vec_str.end(); ++it) {
for(auto &c : *it)
@krysseltillada
krysseltillada / sort_it.cpp
Created May 20, 2015 01:29
bubble sort a vector using iterators
#include <iostream>
#include <vector>
int main()
{
std::vector<int> num = {22, 1, 3, 4, 100, 4, 1, 6, 7};
auto temp = 0, counter = 0;
for(std::vector<int>::iterator it1 = num.begin(); it1 != num.end(); ++it1) {
for(std::vector<int>::iterator it2 = num.begin() + (counter += 1); it2 != num.end(); ++it2) {
@krysseltillada
krysseltillada / adj_pair.cpp
Created May 20, 2015 13:29
adding adjacent pairs using iterators
#include <iostream>
#include <vector>
int main()
{
std::vector<int> vec1 = {5, 6, 7, 8, 9, 10, 11};
auto sum = 0, total = 0;
for(auto it = vec1.begin() + 1; it != vec1.end(); ++it) {
sum = *it + *(it - 1);
@krysseltillada
krysseltillada / gc_it.cpp
Created May 20, 2015 15:04
grade clustering using iterators
#include <iostream>
#include <vector>
int main()
{
std::vector<unsigned> scores(11, 0);
unsigned grade = 0;
auto it = scores.begin();
for(;std::cin >> grade;) {
@krysseltillada
krysseltillada / array_ini.cpp
Created May 21, 2015 14:27
ways of initializing arrays
#include <iostream>
int main()
{
const unsigned MAXNUM = 10;
/// initialize 10 int objects
int num[MAXNUM] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
/// declare 10 int array of pointers
@krysseltillada
krysseltillada / bin_txt.cpp
Created May 21, 2015 16:42
binary to text converter
#include <iostream>
#include <cstdlib>
#include <string>
#include <fstream>
int binary_dec(long);
int main()
{
long bin, num = 0;