Skip to content

Instantly share code, notes, and snippets.

View mshafae's full-sized avatar

Michael Shafae mshafae

View GitHub Profile
@mshafae
mshafae / cpsc120_age.cc
Last active December 13, 2023 23:15
Calculate your age using a constant current year.
// Gist https://gist.github.com/440681ee258659c96d40eb9eb60b14e5
#include <iostream>
#include <string>
const int kThisYear{2022};
int main(int argc, char const *argv[]) {
int your_birth_year{0};
@mshafae
mshafae / cpsc120_command_line_arguments.cc
Last active December 13, 2023 23:16
Command line arguments in C++17 using a vector.
// Gist https://gist.github.com/ed20598a5ccf74be58e34a18e3379ff0
#include <iostream>
#include <string>
#include <vector>
int main(int argc, char const* argv[]) {
std::vector<std::string> command_line_arguments{argv, argv + argc};
std::cout << "There are " << argc << " arguments on the command line.\n";
@mshafae
mshafae / cpsc120_taco_tuesday.cc
Last active December 13, 2023 23:16
if-else if-else example
// Gist https://gist.github.com/8bde313d4a8d491c0229ed30fdad0bc7
#include <iostream>
#include <string>
#include <vector>
int main(int argc, char const* argv[]) {
std::vector<std::string> command_line_arguments{argv, argv + argc};
if (command_line_arguments.size() < 2) {
@mshafae
mshafae / cpsc120_array.cc
Last active September 27, 2022 03:55
Working with C++ arrays (not C arrays).
// Gist https://gist.github.com/29e77a62a20852cb0925aeb5ab840a77
#include <array>
#include <iostream>
using namespace std;
int main(int argc, char const* argv[]) {
std::array<int, 5> even_numbers{2, 4, 6, 8, 10};
@mshafae
mshafae / cpsc120_cmd_line_stoi_stof.cc
Last active December 13, 2023 23:16
CPSC 120 working with stoi and stof
// Gist https://gist.github.com/d8488f24f51eaf25e2213d5091927253
#include <iostream>
#include <vector>
#include <string>
int main(int argc, char const *argv[]) {
std::vector<std::string> arguments = std::vector<std::string>(argv, argv + argc);
for(const std::string& arg : arguments){
@mshafae
mshafae / cpp.json
Last active October 26, 2022 05:51
VS Code snippet for CSUF CPSC header format.
{
// Place your snippets for cpp here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
@mshafae
mshafae / cpsc120_sum.cc
Created October 4, 2022 03:22
Sum all integers provided on the command line.
// Gist https://gist.github.com/83a91cafc678eaf64db6f3ac7d6e5438
#include <iostream>
#include <string>
#include <vector>
int main(int argc, char const *argv[]) {
std::vector<std::string> arguments =
std::vector<std::string>{argv, argv + argc};
@mshafae
mshafae / cpsc120_for_loop_with_reference.cc
Last active December 13, 2023 23:16
Using references and C++ array.
// Gist https://gist.github.com/7323b58b786d7db312a39ab8b0373413
#include <array>
#include <iostream>
#include <string>
int main(int argc, char const* argv[]) {
std::array<int, 5> my_array{11, 12, 13, 14, 15};
// Does not change the values in the array
@mshafae
mshafae / cpsc120_count_to_five.cc
Created October 4, 2022 03:34
Counting to 5 with three different loops.
// Gist https://gist.github.com/268280c9d47f4388b5a74ad22b735cd2
#include <iostream>
const int kMax = 5;
int main(int argc, char const *argv[]) {
std::cout << "Counting to " << kMax << " with a for loop.\n";
for (int counter = 0; counter < kMax; counter++) {
@mshafae
mshafae / cpsc120_while_loop_prompt.cc
Last active October 4, 2022 03:38
Loop until a number is entered that matches the criteria.
// Gist https://gist.github.com/450b2211f29cc7cae4735833f96bdedb
#include <iostream>
int main(int argc, char const *argv[]) {
std::cout << "Enter a number between 10 and 20: ";
int input_number{0};
std::cin >> input_number;
while (input_number < 10 || input_number > 20) {