Simple Operating system

closed account (ozUkoG1T)
Hello I am new to C++ forums anyway with the point i have made an simple Operating system you guys may be think why the heck has he put it in here well the only reason is because it is made in pure basic c++ by the way as my user name is Cyberwarfare i made an Cyberwarfare type game and and an calculator by the way the game is literally very simple any way here is the source code to my Simple OS please inform me about any bugs or any improvements the source code by the way please my name may be differnet as i took quite a lot of usernames for the cyber world but i did not copy any bit of it :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
_____________________/ 
//This program is in many ways like an OS (operating system) this is Version 1 this only features 1 game: Cyberwarfare and one calculator
// Please do not copy  the source of this program and claim it as yours atleast give me a bit of credit sorry for poor spelling and very less commenting  . 
#include<stdio.h>   //preproccer
#include<conio.h>   
#include<iostream>
#include<string.h>
#include<stdlib.h>
#include<time.h>
using namespace std;
int main()
{
char newuser[50];
char newpasswd[50];
char signup[]="Sign";
char wishes[50];        //Intisillisation
char commands[]="Game"; 
char username[50];
char calc[]="Calc";
char user[]="Cyberspace";
char pass[]="asdfjkl";
char server[]="Show";
char smd[]="trojan";
float addnumi;
float addnumii;
int  flob;
char password[50];
time_t now;
time(&now);
epic:
printf("%s", ctime(&now));
cout<<"__________________________________\n";
cout<<"    Cyberscape beta OS v.1.0\n      \n";
cout<<"__________________________________\n";
cout<<"Created and developed by Cyberspace.This program may have some minor bugs.\n";
cout<<"Please report any bugs found to Cyberspace.";
cout<<"\n\n\n";
cout<<"_______________\n";
cout<<"Authentication\n";
cout<<"________________\n";
cout<<"Username: \n";
cin>>username ;
cin.ignore();
cout<<"Password: \n";
cin>>password;
cin.ignore();
if(strcmp(username,user)==0&&strcmp(password,pass)==0)
{ back:
cout<<"Loged in as superuser\n";
cout<<"Welcome to Cyberspace OS\nCommand: ";
cin>>wishes;
if(strcmp(wishes,calc)==0)
{
cout<<"Welcome to simple calculator\n";
cout<<"1.Addition\n";
cout<<"2.Substraction\n";
cout<<"3.Multiplication\n";
cout<<"4.Division\n";
cout<<"5.About calculator\n";
cin>>flob;
switch(flob)
{
             case 1 : 
                  cout<<"Enter 1st number : "; 
                  cin>>addnumi;
                  cout<<"Enter 2nd Number:";
                  cin>>addnumii;
                  cout<<"You're answer is "<<addnumi+addnumii<<endl;    
                  cin.get();
                  goto back;
                  break;
             case 2 : 
                  cout<<"Enter 1st number: ";
                  cin>>addnumi;
                  cout<<"Enter 2nd number: ";
                  cin>>addnumii;
             cout<<"You're answer is: "<<addnumi-addnumii<<endl;
             cin.get();
             goto back;
             break;
             case 3 :
                  cout<<"Enter 1st number: \n";
                  cin>>addnumi;
                  cout<<"Enter 2nd number: \n";
                  cin>>addnumii;
                  cout<<"You're answer is "<<addnumi*addnumii<<endl;
                  cin.get();
                  goto back;
                  break;
                  case 4 :  cout<<"Enter 1st number: \n";
                  cin>>addnumi;
                  cout<<"Enter 2nd number: \n";
                  cin>>addnumii;
                  cout<<"You're answer is "<<addnumi/addnumii<<endl;
                  cin.get();
                  goto back;
                  break;
                  case 5 : cout<<"The creator and developer of this calculator is Cyberspace.\nCyberspace is an";
                  cout<<" enthusiat but an intermediate C/C++ Programmer."<<endl;
                  cout<<"Cyberspace was the developer of the Simple OS\n\n\n";
                  cout<<"The program may be redistrubuted and used \nin other programs no copyright acts will be violanted\n\n";
                  cout<<"\n\n\n\n\n";
                  }   
                  cin.get();
                  goto epic;
                  }                  
if(strcmp(wishes,commands)==0)
{
{
int menu;
char epic[100];
int  start;
char command[50];
char deface[]="Quit";
char closing[]="index";
char server[]="Show";
char twocommand[50];
leg:
cout<<"_______________________________________________\n";        
cout<<"       ***Welcome to Cyberwarfare***           \n";
cout<<"      ~(By Cyberspace)~                        \n";     
cout<<"_______________________________________________\n";
cout<<"\nPlease enter you're name:  " ;
cin>>epic;
cin.ignore();
cout<<"Welcome  "<<epic<<"\n";
cout<<"Please select enter the number: \n";
cout<<"1.Start\n";
cout<<"2.Credits\n";
cin>>menu;
switch(menu)
{
case 1:
monster:
cout<<"         Cyberwar vista OS    \n";
time_t now;
time(&now);
printf("%s", ctime(&now));
cout<<"If you want an hint press cheat \n";                     
cout<<"  Enter password: ";
cin>>start;
cin.ignore ();
switch(start)
{
case 1: cout<<" The password is conecutive number from 1 to 3.  ";
cin.get();
goto monster;
break;
case 123: cout<<"You succsecfully loged on as Superuser\n";
cout<<"\n";
server:
cout<<"Enter Command: \n";
cin>>command;
if(strcmp(command,smd)==0)
{
cout<<"Sterling trojan released intel disrupeted servers partially damaged\n";
cin.get();
goto server;
if(strcmp(command,server)==0)
{
cout<<"Ip addresses:125.937.368 ; 98.678.156 ; 101.65.481 ;125.937.358 ; 99.678.156 ;\n121.65.481 ...\n";
cin.get();
goto server;
}
}        
if(strcmp(command,deface)==0)
{
cout<<"Network connection closed\n";
cout<<"Servers Offline\n";
cout<<"Next comand: \n";
cin>>twocommand;
if(strcmp(twocommand,closing)==0)
{
                                                      cout<<"Deface page uploaded\n";
                        cout<<"Welcome to the new homepage: \n";
                        cout<<"___________________________________________________________________________\n";
                        cout<<"Mozilla firefox-Cyberwar operating system.                                 \n";
                        cout<<"___________________________________________________________________________\n";
                        cout<<"www.cyberwarvistaos.net/index.php \n";           
                        cout<<"___________________________________________________________________________\n";
                        cout<<"#\n";
                        cout<<"#\n";
                        cout<<"#\n";
                        cout<<"#####\n";
                        cout<<"#   #  acked BY Cyberspace Please improve you're security\n";
                        cout<<"       This website is no longer safe all the information is gathered\n";
                        cout<<"      Notice to the public the admin information: Username:Cyberjunkie\n";
                        cout<<"                                                  password:1234567\n";
                        cout<<" The website network servers are offline(You cannot log in)\n........."; 
                        cout<<"_____________________________________________________________________________\n";                    
                     cin.get();
                     
                        
                     }
                     
                     }
cin.get();
break;
default: cout<<"System alert Ip taken: 127.0.0.1 System lockout for 101 hours ERROR.";
cin.get();
}
cin.get();
break;      
case 2: cout<<"Credits\n";
cout<<"Developer: Cybernet\n";
cout<<"beta tester:Cyberenet\n";
cout<<"ASCII artist :Cybernet\n";
cout<<"Bug reporter:Cybernet\n";
cout<<"_________________________________________________________________________\n";
cout<<"This game is under developement please report any bug to the creator";
cout<< "             \nCyberspace games present : Cyberwar\n             \n";
cout<< "              ______________________________________                    \n"; 
goto leg;
cin.get();
break;
default: cout<<"Fatal System error Cyberspace servers renconnecting....\nConnection failure System Virus detected swiping hard drive ";
cin.get();
break;
}
 
     
cin.get();
}

                             cin.get();
                             goto back;
                             }

cin.get();
}
}
C-Strings vs C++ Strings:
You are using C++ yet you still use C-strings? Why is that? You might as well use C if you aren't going to use what C++ provides you with. Trust me, it will make your life a lot easier.

http://www.cprogramming.com/tutorial/string.html

Goto Statements:
They do more harm then good, really. You could easily replace them with some type of loop.

1
2
3
4
5
const char* pass = "derp";
char passInput[50];
while(strcmp(passInput, pass) != 0) {
     std::cin >> passInput;
}

Doesn't that look a lot neater than this..

1
2
3
4
5
6
:backUpAgain
const char* pass = "derp";
char passInput[50];
std::cin >> passInput;
if(strcmp(pass, passInput) != 0)
     goto backUpAgain;



Constant Variables:
You should really use the 'const' keyword if your program isn't going to modify the variable.
Take the 'user' variable for example, you only compare that variable with the data entered by the user, so the contents of the variable will never be changed.

1
2
const char USER[]="Cyberspace";
const char PASS[]="asdfjkl";


Lack of Indention:
This is really just my personal opinion, but I'll say it anyway. You should really indent your code. And I know, you indented some of it, but not all of it. I find it hard to read without indenting it properly.

Using Whole Namespace:
This is another personal opinion of mine, so you don't _have_ to really read this.

Why don't you just use the prefix 'std'? The main problem with this is name conflicts between two namespaces. Now I know, this doesn't apply to this application because you aren't using two namespaces. Using the prefix is just a good habit to pick up on.

1
2
using namespace std;
cout << "hello";

 
std::cout << "hello";

Five more characters isn't much.

Summary:
It really boils down to the goto statements/labels, constant variables and doing things the 'C++ way'.
- Try to break the habit of using goto statments and labels.
- Start using strings instead of character arrays.
- If the program isn't going to alter it then declare it as a constant.
Last edited on
Standard C headers in C++ shall be declared with prefix 'c'. So instead of

1
2
3
4
5
6
#include<stdio.h>   //preproccer
#include<conio.h>   
#include<iostream>
#include<string.h>
#include<stdlib.h>
#include<time.h> 


the following includes shall be


1
2
3
4
5
6
#include<cstdio>   //preproccer
#include<conio.h>   
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<ctime> 



Instead of magic number 50 in the following declarations


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
char newuser[50];
char newpasswd[50];
char signup[]="Sign";
char wishes[50];        //Intisillisation
char commands[]="Game"; 
char username[50];
char calc[]="Calc";
char user[]="Cyberspace";
char pass[]="asdfjkl";
char server[]="Show";
char smd[]="trojan";
float addnumi;
float addnumii;
int  flob;
char password[50];


it would be better to declare some constant. For example

const size_t I_DO_NOT_KNOW_HOW_TO_NAME_THIS_CONSTANT_YET = 50;

Even the simple name N will be better than the magic number

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
const size_t N = 50;
char newuser[N];
char newpasswd[N];
char signup[]="Sign";
char wishes[N];        //Intisillisation
char commands[]="Game"; 
char username[N];
char calc[]="Calc";
char user[]="Cyberspace";
char pass[]="asdfjkl";
char server[]="Show";
char smd[]="trojan";
float addnumi;
float addnumii;
int  flob;
char password[N];


Also it woul be better instead the several arrays

1
2
3
4
5
char calc[]="Calc";
char user[]="Cyberspace";
char pass[]="asdfjkl";
char server[]="Show";
char smd[]="trojan";


to declare one array of const pointers to chhar if these arrays are used only for output their contents.

1
2
 const char *optionNames[] = { "Calc", "Cyberspace", "asdfjkl", "Show", "trojan" };
enum { Calc, Cyberspace, Asdfjkl, Show, Trojan }; // indexes of the array 


Of cource the name of the array you can assign yourself.
Last edited on
closed account (ozUkoG1T)
Thanks for the reply although it may not be OS it seems and simulates how an OS (MS-DOS) works like you enter an command it executes it so anyway thanks for teaching some thing
closed account (ozUkoG1T)
thanks about that so does that mean it could cause some bugs
thanks about that so does that mean it could cause some bugs

Magic numbers do not cause bugs, they are hard-coded numbers that do not have any context. If you leave your project for a while, then come back and look at the number 50 and wonder why did you choose this number, you'll understand the importance of avoiding magic numbers. Also, it would be better if you avoid goto statments.
Last edited on
ahh goto statements, those are nasty.
closed account (ozUkoG1T)
Ah yes i knew it could cause an issue but i am quite used to it as i used to code Batch scripting i know you may not like it but please try read it as goto statements cold make my script like an big messed up knot please try understand it or better try run and compile it in you're machine ( i am not trying to be imperative ) . And i know you do not like goto loops i am trying to change the way myself so please forgive.
you can also do

1
2
3
    char newuser[50], newpasswd[50], signup[]="Sign", wishes[50];
    char commands[]="Game", username[50], calc[]="Calc", user[]="Cyberspace";
    char pass[]="asdfjkl", server[]="Show", smd[]="trojan";


so you dont have so many lines also. you can do all of that on one line but i used 3 for readability.
Last edited on
I would be interested in looking at what it looks like, but can we see some pictures please? Some people might want to see pictures before they skid the code.
I would be interested in looking at what it looks like, but can we see some pictures please? Some people might want to see pictures before they skid the code.


Are you kidding me? The code is there, use it. You aren't 'skidding' the code if you just test it out and then leave a comment on how to improve it.
Topic archived. No new replies allowed.