Coder Social home page Coder Social logo

cpp-fyp-proj's Introduction

This is a web-application to help students in Nanyang Technological University learn Object-Oriented Programming in C++

This was developed as part of the Final Year Project SCSE22-0467-1, Interactive Learning in C++ 
The website is currently hosted here: https://cpp-fyp-proj.vercel.app/



DEV README

1. run compiler service module via poetry 
    curl -sSL https://install.python-poetry.org | python3 -
    poetry install
    poetry run start

2. run frontend via npm
    npm install
    npm start

cpp-fyp-proj's People

Contributors

zhuweiji avatar

Watchers

 avatar

Forkers

rohitk-singh

cpp-fyp-proj's Issues

game: notebook fight

n players race to finish all problems (code editor and mcq) in a notebook

bottom bar shows progress of all players

upon completing every x questions players get a power up
(flash on other screens, font changed to handwritten, invert scroll, no syntax highlighting) that goes to topbar

players can click to activate

2fa emails for ntu accounts

add 2fa and emails tagged to ntu accounts

allow these accounts to run all code
create whitelist of safe libs that can be included (aka iostream okay but not fstream because it allows write,delete of files)
compiler should be able to check for non-whitelisted stdlib includes and deny
user model should have ntu-tag to indicate trusted
if trusted users compile non-whitelisted includes then log their email in case they cause server to go down

redirect std::cin or the server will hang while waiting for input

using namespace std;
#include <bits/stdc++.h>

// put below redirect functionality somewhere

    std::ifstream cin(R"(filepath_here");    // raw string

    // optional performance optimizations    
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0);

    std::cin.rdbuf(cin.rdbuf());

fill in tutorial 1

hello world

main method, #include, std functions : cin and cout
std::endl vs \n
std::getline()

#instantialization

int a; // no initializer (default initialization)
int b = 5; // initializer after equals sign (copy initialization)
int c( 6 ); // initializer in parenthesis (direct initialization)

// List initialization methods (C++11)
int d { 7 }; // initializer in braces (direct list initialization)
int e = { 8 }; // initializer in braces after equals sign (copy list initialization)
int f {}; // initializer is empty braces (value initialization)

Default initialization is when a variable initialization has no initializer (e.g. int x;). In most cases, the variable is left with an indeterminate value.

Value initialization is when a variable initialization has an empty brace (e.g. int x{};). In most cases this will perform zero-initialization.

You should prefer value initialization to default initialization.

#Preprocessor directives

instructions that start with a # symbol and end with a newline (NOT a semicolon).

the #include directive
You’ve already seen the #include directive in action (generally to #include ). When you #include a file, the preprocessor replaces the #include directive with the contents of the included file. The included contents are then preprocessed (along with the rest of the file), and then compiled.

The #define directive can be used to create a macro. In C++, a macro is a rule that defines how input text is converted into replacement output text.
For general readability, you’ll generally want to #define identifiers outside of functions.

#ifdef, #ifndef, and #endif.

#include

#define PRINT_JOE

int main()
{
#ifdef PRINT_JOE
std::cout << "Joe\n"; // will be compiled since PRINT_JOE is defined
#endif

#ifdef PRINT_BOB
std::cout << "Bob\n"; // will be ignored since PRINT_BOB is not defined
#endif

return 0;

}

only #define directives only last until the end of the file they are declared in

forward declarations and header files

int main(){
int x = add(1,2)

function definition vs function declaration

header guards

#ifndef SQUARE_H
#define SQUARE_H

int getSquareSides()
{
return 4;
}

#endif

use predefined functions to create a calculator

data structures

sizeof

ints

short, int, long, long long
integer overflow
integer division
avoid unsigned ints if possible - https://google.github.io/styleguide/cppguide.html#Integer_Types
fixed-width integers

float

float, double, long double
floating point problems

booleans

bool
narrowing

chars

strings

c-style strings (double quotes)
std::string
std::ws to remove leading whitespace (std::getline(std::cin, name); vs std::getline(std::cin>> std::ws, name);

static_cast

static_cast(5.5)
std::cout << ch << " has value " << static_cast(ch) << '\n'; // print value of variable ch as an int
The static_cast operator will produce undefined behavior if the value being converted doesn’t fit in range of the new type.

const

must be initialized
dont use const in function parameters and return values
symbolic constants (#define) -- prefer const in code to symbolic constants for autocomplete and to avoid name collisions with variables ( to prevent accidentally overriding variables)

extra: https://www.learncpp.com/cpp-tutorial/compile-time-constants-constant-expressions-and-constexpr/

literals

values that are unnamed and who's values cannot be changed (int length__meters = length__feet * 3.28084)
Just like objects have a type, all literals have a type. The type of a literal is deduced from the literal’s value. For example, a literal that is a whole number (e.g. 5) is deduced to be of type int.

Literal suffixes

float f { 4.1 }; // warning: 4.1 is a double literal, not a float literal
float f { 4.1f }; // use 'f' suffix so the literal is a float and matches variable type of float
double d { 4.1 }; // change variable to type double so it matches the literal type double

scientific notation

double avogadro { 6.02e23 }; // 6.02 x 10^23 is a double literal in scientific notation

magic numbers

name literals whose meanings may be unclear
link (may contains profanity): https://en.wikipedia.org/wiki/Fast_inverse_square_root#Overview_of_the_code

Prefer literal suffix L (upper case) over l (lower case).

octal and hexadecimal literals

octal prefix: 0
hex prefix: 0x

std::dec, std::oct, and std::hex I/O manipulators
#include /std::bitset

namespacing

namespace weirdMath{ // define a namespace named foo
int calculateSalary(int daysWorked, int basePay){ return xy3;}
}

int calculateSalary(int daysWorked, int basePay){ return x*y;}

int myPay = weirdMath::calculateSalary(24,10);
int coworkersPay = calculateSalary(24,10);

no name prefix: global namespace -- useful when used within a namespace

::calculateSalary()

multiple namespace

declaring the same namespace in multiple files will combine all the declarations into the same namespace (eg std)

namespace alias

snatch game

two/more players have to react quickly to snatch a bug/issue/enhancement

first person gets to attempt under time limit
if fail/over time limit then other person gets a shot

both can see a single editor

healthchecks for container

confirm functionality of healthchecks in docker container on northflank

include testing if sudo rm -rf / is run on the container

update editor to be able to handle multiple files

parse the code in all files in the current editor
put into json and send to backend
backend compiles all files tgt and send back output

on compile can save object to localstorage to save last progress (maybe)
on refreshing the page can reload this data

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.