Skip to content

Instantly share code, notes, and snippets.

@LauraKirby
Last active September 1, 2017 03:25
Show Gist options
  • Save LauraKirby/47b3762148a1acdd533fb4a585223723 to your computer and use it in GitHub Desktop.
Save LauraKirby/47b3762148a1acdd533fb4a585223723 to your computer and use it in GitHub Desktop.
CCSF: CS 110C-Data Structures & Algorithms C++ (Class 2)
// C++ styleguide: https://google.github.io/styleguide/cppguide.html
// in class video: https://youtu.be/p60rN9JEapg
#include <iostream>
#include "namespace.h"
int main(int argc, const char * argv[]) {
// strings are immutable
std::string hello = "Hello, World!\n";
std::cout << hello;
// prompt: get some value from the command line and print
std::string userInput;
// at this point in your program, you will click on the
// console, enter some input and then press 'enter' to continue.
std::cin >> userInput;
std::cout << userInput << std::endl;
// use custom namespace 'lk'
lk::cout();
// prompt: write a 'for loop' that sums all of the numbers from 1 to 9
int total = 0;
for(int i = 1; i <= 9; i++){
total += i;
}
std::cout << "total: " << total << std::endl;
// prompt: print powers of 3 up to the 10th power
int i = 1;
int result = 1;
while (i <= 10){
i ++;
result *= 3;
std::cout << "powers of 3: " << result << std::endl;
}
return 0;
}
#include <iostream>
// function implementation
namespace lk {
void cout(){
std::cout << "cs course\n";
}
}
#ifndef namespace_h
#define namespace_h
// function prototype
namespace lk {
void cout();
}
#endif /* namespace_h */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment