C_CPP/03_FLOW/MP/main_mp2_FLOW_a.cpp

192 lines
3.1 KiB
C++
Raw Normal View History

2018-03-09 09:47:53 +01:00
#include <stdio.h> /* file main_mp2_FLOW_a.cpp */
2018-08-19 18:48:08 +02:00
#include "../../helpers/AnsiConsole.h"
2018-03-09 09:47:53 +01:00
//TODO: verstehen
2018-03-09 09:47:53 +01:00
AnsiConsole console; int firstLine; int currentTick; Colors currentColor;
#define INITPRINT(label) {firstLine=__LINE__;console.printText(2*currentTick,0,label,Colors::BLACK);}
#define PRINT printLineNumber(__LINE__)
void printLineNumber(int lineNumber);
void recurse(int); // forward declaration because of firstLine initialization
void start_Recursion(){
INITPRINT("Recursion");
PRINT;recurse(10);
PRINT;
}
void recurse(int turns){
PRINT; if(turns>0){
PRINT; recurse(turns - 1);
}
PRINT;
}
2018-03-27 21:54:10 +02:00
void test_Iteration() {
INITPRINT("Test Iteration");
int array[6] = {};
for(int i = 0; i <= 6; i++) {
PRINT; array[i] = 0;
}
}
void test() {
INITPRINT("Test");
int array[6] = {};
PRINT; array[0] = 0;
PRINT; array[1] = 0;
PRINT; array[2] = 0;
PRINT; array[3] = 0;
PRINT; array[4] = 0;
PRINT; array[5] = 0;
}
2018-03-09 09:47:53 +01:00
void start_Sequence(void){
INITPRINT("Sequence");
PRINT;
PRINT;
PRINT;
PRINT;
PRINT;
PRINT;
PRINT;
PRINT;
PRINT;
PRINT;
}
void start_SeqSelection(void){
INITPRINT("Selection");
PRINT; int b = 1;
PRINT; if (b == 1){
PRINT;
PRINT;
PRINT;
PRINT;
PRINT; }else{
PRINT;
PRINT;
PRINT;
PRINT;
PRINT;
}PRINT;
PRINT;
}
void start_Iteration(void){
INITPRINT("Iteration");
PRINT; int i=9;
PRINT; while(i>=0){
PRINT; i--;
}PRINT;
PRINT;
}
int func_1(int arg);
// Sequence, Selection, Iteration, Subroutine
void start_subroutine(void){
INITPRINT("Subroutine");
PRINT; func_1(1);
PRINT; func_1(1);
PRINT;
}
int func_1(int arg){
PRINT; int local_1;
PRINT;
PRINT;
PRINT;
PRINT; return arg * local_1;
}
2018-04-09 20:11:03 +02:00
void modifikation1();
void modifikation2();
2018-03-09 09:47:53 +01:00
int main(int argc, const char * argv[]) {
2018-04-09 20:11:03 +02:00
/*
2018-03-09 09:47:53 +01:00
console.clearScreen();
2018-03-27 21:54:10 +02:00
2018-03-09 09:47:53 +01:00
currentColor = Colors::BLUE;
start_Sequence();
currentColor = Colors::RED;
start_SeqSelection();
currentColor = Colors::YELLOW;
start_subroutine();
currentColor = Colors::GREEN;
start_Iteration();
currentColor = Colors::CYAN;
start_Recursion();
//start_goto();
//start_switch();
//start_interrupt();
//start_coroutine();
//start_exception();
2018-03-27 21:54:10 +02:00
currentColor = Colors::WHITE;
test_Iteration();
currentColor = Colors::MAGENTA;
test();
2018-04-09 20:11:03 +02:00
*/
console.clearScreen();
currentColor = Colors::BLUE;
modifikation1();
currentColor = Colors::RED;
modifikation2();
2018-03-27 21:54:10 +02:00
2018-03-09 09:47:53 +01:00
std::string s;
std::cin >> s;
2018-04-09 20:11:03 +02:00
2018-03-09 09:47:53 +01:00
return 0;
}
2018-04-09 20:11:03 +02:00
void modifikation1() {
INITPRINT("Modifikation 1");
PRINT;
PRINT;
PRINT;
PRINT;
PRINT;
}
void modifikation2() {
}
2018-03-09 09:47:53 +01:00
void printLineNumber(int lineNumber){
std::string line = std::to_string(lineNumber);
currentTick++;
console.printText(currentTick*2-1, 1+lineNumber-firstLine, line, currentColor);
}
/*void printLineNumber(int lineNumber){
std::string line = std::to_string(lineNumber);
console.printText(currentTick*2, 1+lineNumber-firstLine, line, currentColor);
currentTick++;
}*/