Skip to content

Commit 3db5dee

Browse files
committed
Add calc and license commands
1 parent 99f4326 commit 3db5dee

File tree

7 files changed

+164
-9
lines changed

7 files changed

+164
-9
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# NShell Changelog
22

3+
## Build 7
4+
5+
- Introducing "calc", a simple calculator integrated into NShell.
6+
- Also, you can see the license with the "license" command.
7+
38
## Build 6
49

510
- ErikTheRDev added contrib to list the contributors in NShell.

NShell.depend

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
# depslib dependency file v1.0
2-
1681493466 source:d:\nicos code\shell\nshell\nshell\main.cpp
2+
1682249258 source:d:\nicos code\shell\nshell\nshell\main.cpp
33
"help.h"
4+
"calc.h"
45
<iostream>
56

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

8-
1681999616 source:d:\nicos code\shell\nshell\nshell\help.cpp
9+
1682249424 source:d:\nicos code\shell\nshell\nshell\help.cpp
910
"help.h"
1011
<iostream>
1112

13+
1682247462 d:\nicos code\shell\nshell\nshell\calc.h
14+
15+
1682249520 source:d:\nicos code\shell\nshell\nshell\calc.cpp
16+
"calc.h"
17+
<iostream>
18+

NShell.layout

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
22
<CodeBlocks_layout_file>
33
<FileVersion major="1" minor="0" />
4-
<ActiveTarget name="Debug" />
5-
<File name="help.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
4+
<ActiveTarget name="Release" />
5+
<File name="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
66
<Cursor>
7-
<Cursor1 position="330" topLine="0" />
7+
<Cursor1 position="613" topLine="7" />
88
</Cursor>
99
</File>
10-
<File name="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
10+
<File name="help.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
1111
<Cursor>
12-
<Cursor1 position="787" topLine="3" />
12+
<Cursor1 position="347" topLine="0" />
1313
</Cursor>
1414
</File>
1515
</CodeBlocks_layout_file>

calc.cpp

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#include "calc.h"
2+
#include <iostream>
3+
4+
void add(double x, double y)
5+
{
6+
std::cout << x << " + " << y << " = " << x + y << "\n";
7+
}
8+
9+
void subtract(double x, double y)
10+
{
11+
std::cout << x << " - " << y << " = " << x - y << "\n";
12+
}
13+
14+
void multiply(double x, double y)
15+
{
16+
std::cout << x << " * " << y << " = " << x * y << "\n";
17+
}
18+
19+
void divide(double x, double y)
20+
{
21+
if (y != 0) {
22+
std::cout << x << " / " << y << " = " << x / y << "\n";
23+
}
24+
25+
else {
26+
std::cout << "NShell encountered an error: Cannot divide by zero.\n";
27+
}
28+
}
29+
30+
void calc()
31+
{
32+
std::string confirm;
33+
34+
while (true) {
35+
std::cout << "Please type in the first number: ";
36+
double x{ };
37+
std::cin >> x;
38+
39+
std::cout << "Please type in the second number: ";
40+
double y{ };
41+
std::cin >> y;
42+
43+
while (true) {
44+
std::cout << "Please choose what to do.\n\n";
45+
std::cout << "1. Add\n";
46+
std::cout << "2. Subtract\n";
47+
std::cout << "3. Multiply\n";
48+
std::cout << "4. Divide\n";
49+
std::cout << "5. Enter other numbers\n";
50+
int sel{ };
51+
std::cin >> sel;
52+
53+
switch (sel)
54+
{
55+
case 1:
56+
add(x, y);
57+
break;
58+
59+
case 2:
60+
subtract(x, y);
61+
break;
62+
63+
case 3:
64+
multiply(x, y);
65+
break;
66+
67+
case 4:
68+
divide(x, y);
69+
break;
70+
71+
case 5:
72+
break;
73+
74+
default:
75+
std::cout << "NShell encountered an error: Please choose a number between 1 and 5.\n";
76+
}
77+
78+
std::cout << "Do you want to re-run? (Y/N): ";
79+
std::cin >> confirm;
80+
81+
if (confirm == "Y" || confirm == "y" || confirm == "N" || confirm == "n") {
82+
break;
83+
}
84+
85+
else {
86+
std::cout << "NShell encountered an error: Please type Y or N.\n";
87+
}
88+
}
89+
90+
if (confirm == "N" || confirm == "n") {
91+
break;
92+
}
93+
94+
}
95+
96+
}

calc.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef CALC_H_INCLUDED
2+
#define CALC_H_INCLUDED
3+
4+
void add(double x, double y);
5+
void subtract(double x, double y);
6+
void multiply(double x, double y);
7+
void divide(double x, double y);
8+
void calc();
9+
10+
#endif // CALC_H_INCLUDED

help.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ void help_generic() {
66
std::cout << "version - Shows the NShell build number.\n";
77
std::cout << "c.version - Same as version, but in a single line.\n";
88
std::cout << "contrib - Lists all contributors of NShell.\n";
9+
std::cout << "license - Shows the license of NShell.\n";
10+
std::cout << "calc - A basic calculator included in the NShell.\n";
911
std::cout << "exit - Closes the NShell.\n";
1012
}

main.cpp

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,31 @@
11
#include "help.h"
2+
#include "calc.h"
23
#include <iostream>
34

4-
int buildNr = 6;
5+
int buildNr = 7;
6+
7+
const char *mitLicense =
8+
"MIT License\n\n"
9+
10+
"Copyright (c) 2023 Nicolas Lucien and NShell contributors\n\n"
11+
12+
"Permission is hereby granted, free of charge, to any person obtaining a copy "
13+
"of this software and associated documentation files (the \"Software\"), to deal "
14+
"in the Software without restriction, including without limitation the rights "
15+
"to use, copy, modify, merge, publish, distribute, sublicense, and/or sell "
16+
"copies of the Software, and to permit persons to whom the Software is "
17+
"furnished to do so, subject to the following conditions:\n\n"
18+
19+
"The above copyright notice and this permission notice shall be included in all "
20+
"copies or substantial portions of the Software.\n\n"
21+
22+
"THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR "
23+
"IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, "
24+
"FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE "
25+
"AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER "
26+
"LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, "
27+
"OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE "
28+
"SOFTWARE.\n";
529

630
int main()
731
{
@@ -30,12 +54,23 @@ int main()
3054
help_generic();
3155
}
3256

57+
else if (command_to_run == "calc") {
58+
calc();
59+
}
60+
61+
else if (command_to_run == "license") {
62+
std::cout << "NShell\n" << "Build " << buildNr << '\n';
63+
std::cout << "\n";
64+
65+
std::cout << mitLicense;
66+
}
67+
3368
else if (command_to_run == "exit") {
3469
break;
3570
}
3671

3772
else {
38-
std::cout << "Unknown command!\n";
73+
std::cout << "NShell encountered an error: Unknown command!\n";
3974
}
4075
}
4176

0 commit comments

Comments
 (0)