zhuweiji / cpp-fyp-proj Goto Github PK
View Code? Open in Web Editor NEWHome Page: cpp-fyp-proj.vercel.app
Home Page: cpp-fyp-proj.vercel.app
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
change parse split lines to look behind and in front for component or code block tags
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
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
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());
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
int main(){
int x = add(1,2)
function definition vs function declaration
#ifndef SQUARE_H
#define SQUARE_H
int getSquareSides()
{
return 4;
}
#endif
sizeof
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, double, long double
floating point problems
bool
narrowing
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(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.
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)
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.
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
double avogadro { 6.02e23 }; // 6.02 x 10^23 is a double literal in scientific notation
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 prefix: 0
hex prefix: 0x
std::dec, std::oct, and std::hex I/O manipulators
#include /std::bitset
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);
::calculateSalary()
declaring the same namespace in multiple files will combine all the declarations into the same namespace (eg std)
so all other pages can fill up screen
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
confirm functionality of healthchecks in docker container on northflank
include testing if sudo rm -rf / is run on the container
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.