diff --git a/complex/complex.cpp b/complex/complex.cpp index 8f52bb3..1385e4d 100644 --- a/complex/complex.cpp +++ b/complex/complex.cpp @@ -1,23 +1,44 @@ -// complex.cpp -// Multiplying complex numbers - #include -#include // required for the complex class +#include using namespace std; -int main() -{ - complex num1{ 2.0, 2.0 }; // using C++11 uniform initialisation syntax - complex num2{ 4.0, -2.0 }; // old syntax: complex num2(4.0,-2.0); +using Comp = complex; + +int main() { + + Comp a = 0.0; + Comp b = 0.0; + Comp c = 0.0; + char Continue; + + while(Continue != 'q'){ + + cout << "Please enter a :" << endl; + cin >> a; + cout << "Please enter b :" << endl; + cin>> b; + cout << "Please enter c :" << endl; + cin >> c; + - auto answer = num1 * num2; // using C++11 auto keyword, - // answer is of type: complex +Comp Root = sqrt(pow(b,2) -4.0*a*c); - cout << "The answer is: " << answer << endl; - cout << "Or in a more familiar form: " << answer.real() << " + " << answer.imag() << "j" << endl; +Comp answer1 = (-b + Root)/(2.0*a); - // answer++; +Comp answer2 = (-b - Root)/(2.0*a); + +cout << "The roots are: " << answer1.real() << " + " <> Continue; + + + } return 0; } + diff --git a/guessing-game.cpp b/guessing-game.cpp new file mode 100644 index 0000000..8625ff0 --- /dev/null +++ b/guessing-game.cpp @@ -0,0 +1,48 @@ +#include +#include +#include + +using namespace std; + +int main() { + + int UserGuess = 0 ; + int RandNum = 0; + int TurnCounter = 0; + + srand(time(0)); + + RandNum =rand() % 100+1; + + + cout <<"Please enter your guess."<> UserGuess; + + if (TurnCounter ==4 && UserGuess!=RandNum){ + cout<< "You lose"<RandNum){ + cout << "Guess lower" < @@ -7,27 +7,42 @@ using namespace std; int main() { Screen myScreen{6,6}; - - myScreen.forward(); - myScreen.set('*'); - myScreen.down(); + + myScreen.clear(' '); + myScreen.move(1,3); myScreen.set('*'); - myScreen.move(3,3); - myScreen.set("---"); - - myScreen.display(); - cout << endl; - - myScreen.reSize(16,16); - myScreen.display(); - myScreen.clear(' '); - - myScreen.move(7,7); - myScreen.set("BIG"); - myScreen.move(8,5); - myScreen.set("SCREEN"); - myScreen.display(); - - return 0; + myScreen.forward(); + myScreen.set('*'); + myScreen.move(2,2); + myScreen.set('*'); + myScreen.move(2,5); + myScreen.set('*'); + myScreen.move(3,6); + myScreen.set('*'); + myScreen.move(3,1); + myScreen.set('*'); + myScreen.move(4,1); + myScreen.set('*'); + myScreen.forward(); + myScreen.set('*'); + myScreen.forward(); + myScreen.set('*'); + myScreen.forward(); + myScreen.set('*'); + myScreen.forward(); + myScreen.set('*'); + myScreen.forward(); + myScreen.set('*'); + myScreen.move(5,1); + myScreen.set('*'); + myScreen.move(6,1); + myScreen.set('*'); + myScreen.move(5,6); + myScreen.set('*'); + myScreen.move(6,6); + myScreen.set('*'); + + myScreen.display(); + + return 0; } - diff --git a/screen/screen.cpp b/screen/screen.cpp index 12d8625..0ecac6a 100644 --- a/screen/screen.cpp +++ b/screen/screen.cpp @@ -13,6 +13,49 @@ Screen::Screen(string::size_type height, string::size_type width, char bkground) // character value of bkground { /* all the work is done with the member initialization list */ } +void Screen::EmptySquare(unsigned int x,unsigned int y, unsigned int length){ // x and y are the cords of the top left corner with length + + if(x + (length-1) > _width){ + + cerr<<"Not enough space for entered dimensions" << endl; + return; + } + + if(y + (length-1) > _height){ + + cerr<<"Not enough space for entered dimensions" << endl; + return; + + } + + + clear(' '); + move(x,y); // sets original starting position + set('*'); + + for(int j =0; j + using namespace std; -// returns the amount of time in seconds that has passed since the process (i.e. your program) started executing + // returns the amount of time in seconds that has passed since the process (i.e. your program) started executing double getProcessTime() { - clock_t time = clock(); - return static_cast(time)/CLOCKS_PER_SEC; + clock_t time = clock(); + return static_cast(time)/CLOCKS_PER_SEC; +} + +StopWatch::StopWatch( double startTime, double endTime): _startTime(startTime), _endTime(endTime){}; + +void StopWatch::StartWatch() +{ + _startTime = getProcessTime(); + return; +} + +void StopWatch::EndWatch() +{ + _endTime = getProcessTime(); +} + +void StopWatch::ResetWatch() +{ + _startTime = 0; + _endTime = 0; } + +double StopWatch::getFunctionTime() // calculate the lapsed time in calculating function +{ + return _endTime - _startTime; +} + diff --git a/stopwatch/StopWatch.h b/stopwatch/StopWatch.h index 7e99fd0..ad4387e 100644 --- a/stopwatch/StopWatch.h +++ b/stopwatch/StopWatch.h @@ -1,8 +1,22 @@ #ifndef STOPWATCH_H #define STOPWATCH_H -// returns the amount of time in seconds that has passed since the process (i.e. your program) started executing + // returns the amount of time in seconds that has passed since the process (i.e. your program) started executing double getProcessTime(); - -#endif +class StopWatch{ + +public: + + StopWatch( double startTime = 0, double endTime = 0 ); // class constructor + void StartWatch(); // stopwatch start function + void EndWatch(); // stopwatch end funtion + void ResetWatch(); // stop watch reset function + double getFunctionTime(); // caluclating the time lasped in the process being timed +private: + + double _startTime; + double _endTime; + }; + +#endif \ No newline at end of file diff --git a/stopwatch/Stopwatch_Main.cpp b/stopwatch/Stopwatch_Main.cpp new file mode 100644 index 0000000..87c595a --- /dev/null +++ b/stopwatch/Stopwatch_Main.cpp @@ -0,0 +1,33 @@ +#include "StopWatch.h" +#include +#include + +using namespace std; + +void FunctionInQuestion(); + +int main() +{ + StopWatch NewWatch; // declare object NewWatch + NewWatch.StartWatch(); // start the time for the stop watch + //Function Start + FunctionInQuestion(); // run the function to be timed + //Function End + NewWatch.EndWatch(); // stop the time + + cout << "The function took "<< NewWatch.getFunctionTime() << " seconds" << endl; + NewWatch.ResetWatch(); // the reset function to clear previous time + cout << NewWatch.getFunctionTime() << " -the Stopwatch has been reset" << endl; + return 0; +} + +void FunctionInQuestion() +{ + int i = 0; + while(i != 1000000000) + { + i++; + } + + return; +}