Skip to content

Commit

Permalink
Add calc and license commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Tech-FZ committed Apr 23, 2023
1 parent 99f4326 commit 3db5dee
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# NShell Changelog

## Build 7

- Introducing "calc", a simple calculator integrated into NShell.
- Also, you can see the license with the "license" command.

## Build 6

- ErikTheRDev added contrib to list the contributors in NShell.
Expand Down
11 changes: 9 additions & 2 deletions NShell.depend
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
# depslib dependency file v1.0
1681493466 source:d:\nicos code\shell\nshell\nshell\main.cpp
1682249258 source:d:\nicos code\shell\nshell\nshell\main.cpp
"help.h"
"calc.h"
<iostream>

1681493184 d:\nicos code\shell\nshell\nshell\help.h

1681999616 source:d:\nicos code\shell\nshell\nshell\help.cpp
1682249424 source:d:\nicos code\shell\nshell\nshell\help.cpp
"help.h"
<iostream>

1682247462 d:\nicos code\shell\nshell\nshell\calc.h

1682249520 source:d:\nicos code\shell\nshell\nshell\calc.cpp
"calc.h"
<iostream>

10 changes: 5 additions & 5 deletions NShell.layout
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="help.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<ActiveTarget name="Release" />
<File name="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="330" topLine="0" />
<Cursor1 position="613" topLine="7" />
</Cursor>
</File>
<File name="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="help.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="787" topLine="3" />
<Cursor1 position="347" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>
96 changes: 96 additions & 0 deletions calc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#include "calc.h"
#include <iostream>

void add(double x, double y)
{
std::cout << x << " + " << y << " = " << x + y << "\n";
}

void subtract(double x, double y)
{
std::cout << x << " - " << y << " = " << x - y << "\n";
}

void multiply(double x, double y)
{
std::cout << x << " * " << y << " = " << x * y << "\n";
}

void divide(double x, double y)
{
if (y != 0) {
std::cout << x << " / " << y << " = " << x / y << "\n";
}

else {
std::cout << "NShell encountered an error: Cannot divide by zero.\n";
}
}

void calc()
{
std::string confirm;

while (true) {
std::cout << "Please type in the first number: ";
double x{ };
std::cin >> x;

std::cout << "Please type in the second number: ";
double y{ };
std::cin >> y;

while (true) {
std::cout << "Please choose what to do.\n\n";
std::cout << "1. Add\n";
std::cout << "2. Subtract\n";
std::cout << "3. Multiply\n";
std::cout << "4. Divide\n";
std::cout << "5. Enter other numbers\n";
int sel{ };
std::cin >> sel;

switch (sel)
{
case 1:
add(x, y);
break;

case 2:
subtract(x, y);
break;

case 3:
multiply(x, y);
break;

case 4:
divide(x, y);
break;

case 5:
break;

default:
std::cout << "NShell encountered an error: Please choose a number between 1 and 5.\n";
}

std::cout << "Do you want to re-run? (Y/N): ";
std::cin >> confirm;

if (confirm == "Y" || confirm == "y" || confirm == "N" || confirm == "n") {
break;
}

else {
std::cout << "NShell encountered an error: Please type Y or N.\n";
}
}

if (confirm == "N" || confirm == "n") {
break;
}

}

}
10 changes: 10 additions & 0 deletions calc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef CALC_H_INCLUDED
#define CALC_H_INCLUDED

void add(double x, double y);
void subtract(double x, double y);
void multiply(double x, double y);
void divide(double x, double y);
void calc();

#endif // CALC_H_INCLUDED
2 changes: 2 additions & 0 deletions help.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ void help_generic() {
std::cout << "version - Shows the NShell build number.\n";
std::cout << "c.version - Same as version, but in a single line.\n";
std::cout << "contrib - Lists all contributors of NShell.\n";
std::cout << "license - Shows the license of NShell.\n";
std::cout << "calc - A basic calculator included in the NShell.\n";
std::cout << "exit - Closes the NShell.\n";
}
39 changes: 37 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,31 @@
#include "help.h"
#include "calc.h"
#include <iostream>

int buildNr = 6;
int buildNr = 7;

const char *mitLicense =
"MIT License\n\n"

"Copyright (c) 2023 Nicolas Lucien and NShell contributors\n\n"

"Permission is hereby granted, free of charge, to any person obtaining a copy "
"of this software and associated documentation files (the \"Software\"), to deal "
"in the Software without restriction, including without limitation the rights "
"to use, copy, modify, merge, publish, distribute, sublicense, and/or sell "
"copies of the Software, and to permit persons to whom the Software is "
"furnished to do so, subject to the following conditions:\n\n"

"The above copyright notice and this permission notice shall be included in all "
"copies or substantial portions of the Software.\n\n"

"THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR "
"IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, "
"FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE "
"AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER "
"LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, "
"OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE "
"SOFTWARE.\n";

int main()
{
Expand Down Expand Up @@ -30,12 +54,23 @@ int main()
help_generic();
}

else if (command_to_run == "calc") {
calc();
}

else if (command_to_run == "license") {
std::cout << "NShell\n" << "Build " << buildNr << '\n';
std::cout << "\n";

std::cout << mitLicense;
}

else if (command_to_run == "exit") {
break;
}

else {
std::cout << "Unknown command!\n";
std::cout << "NShell encountered an error: Unknown command!\n";
}
}

Expand Down

0 comments on commit 3db5dee

Please sign in to comment.