-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew.cpp
More file actions
175 lines (159 loc) · 5.71 KB
/
new.cpp
File metadata and controls
175 lines (159 loc) · 5.71 KB
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
/*
Project Details
Subject: Programming Concept
Subject Details: DIT1253_202003_1
Assignment Group: Group ?
Group Members:
- Zhao Xuanao (20023404)
- Hee Kar Yan ()
- Maisaa Ahmed ()
Begain Date: (WED) 13 MAY 2020
Lecturer:
Ms. Kumatha
kumatham@sunway.edu.my
016-5636585
*/
#include <iostream> //standart console io
#include <sstream> //stringstream
#include <fstream> //file io
#include <string> //using string
#include <cctype> //using tolower for charactor types
using namespace std;
//inits
int VERSION = 2; //version of this program
string COPYRIGHT = "CikKoo Comm Ltd"; //not an actual copyright
ofstream logFile("log"); //open an log file to put logs
int RETURN_CODE; //assign to this variable to define return code, 0 for normal exit, 1 for error.
bool DEBUG_MODE = false; //if debug mode, Logs will be printed to stdout and stderr.
//user inputs
char planTypeSelected; //stores the plantype that user inputted
int planSpeedSelected; //stores the planspeed as integer from user. example: 30 for 30Mbps
//log function (suppose to be in Logging.cpp). errtype E for Error, S for standard log, W for Warning
void logToFile(string message, char errtype) {
stringstream logMessage;
logMessage << endl << "[" << errtype << "]" << message;
logFile << logMessage.str();
if (DEBUG_MODE){
if (errtype == 'E') cerr<<logMessage.str();
else cout <<logMessage.str();
}
return;
}
//Error (suppose to be in Error.cpp)
class Error{
public:
int code;
string position, description;
//constructor
Error(int argCode,string argPosition,string argDescription){
code = argCode; //Error Code for faster tracing.
position = argPosition; //Error Position, which function did it happened.
description = argDescription; //Error Description, description of error.
}
//returns log message for logging
string getLogMsg(){
stringstream logMessage;
logMessage << "Error occured at: " << position << ", ErrCode: " << code << ", Description: " << description;
return logMessage.str();}
};
//Plan Class, Each store information about different Plans (suppose to be in Plans.cpp)
class Plan{
public:
int speed,price;
string vc,quota;
Plan(int argSpeed,int argPrice,string argVC,string argQuota){
speed = argSpeed;
price = argPrice;
vc = argVC;
quota = argQuota;
}
};
//bisnuess plans in a array
Plan bisnuessPlans[3] = {
Plan(100,129,"Free for CikKoo Line","500Mb"),
Plan(300,189,"Free","Unlimited"),
Plan(500,259,"Free","Unlimited")
}
//home plans in a array
Plan homePlans[3] = {
Plan(30,89,"Free for CikKoo Line","200Mb"),
Plan(100,119,"Free","Unlimited"),
Plan(300,179,"Free","Unlimited")
}
//Intercace, Functions that user will use directly (suppose in Interface.cpp)
namespace Interface {
//Show Company Name, Copyright Info, Explnation about the system etc.
void greetings(){
logToFile("Begain: Interface::greetings()",'S');
cout<<" _____ _ _ _ __ _____ \n / ____(_) | | |/ / / ____| \n | | _| | _| ' / ___ ___ | | ___ _ __ ___ _ __ ___ \n | | | | |/ / < / _ \\ / _ \\ | | / _ \\| '_ ` _ \\| '_ ` _ \\ \n | |____| | <| . \\ (_) | (_) | | |___| (_) | | | | | | | | | | |\n \\_____|_|_|\\_\\_|\\_\\___/ \\___/ \\_____\\___/|_| |_| |_|_| |_| |_|"<<endl;
cout<<"Copyright (c) "<<COPYRIGHT<<", All Rights Reserved."<<endl;
cout<<"Thanks for using CikKoo Comm Internet Plan Auto Selector Ver "<<VERSION<<" !"<<endl;
cout<<endl<<"This system will help you to select the best plan of your need,\nand process your request automatically!"<<endl;
cout<<"Enter some of your requirements to begain!"<<endl;
logToFile("End: Interface::greetings()",'S');
return;
}
//Get User Input for Plan Type, Return 'H' for home, 'B' for bisnuess
char getPlanType(){
logToFile("Begain: Interface::getPlanType()",'S');
char returnVal,filtred;
string raw;
while(true){
cout<<"Are you applying for Home(H) or Bisnuess(B)?"<<endl;
cout<<"Please type H or B following with [enter]. (Case sensitive):";
cin>>raw; filtred = raw[0]; //Get the first charactor
if(filtred == 'H'|filtred == 'B') {
returnVal = filtred;
break;
}
cout<<"You have entered an invalid option. Please enter either H or B only!"<<endl;
logToFile("Invalid option has been inputted, re-executing.",'W');
}
logToFile("End: Interface::getPlanType()",'S');
return returnVal;
}
//Get user input for Plan Speed, Return the Plan Speed as Integer
int getPlanSpeed(char planType){
logToFile("Begain: Interface::getPlanSpeed()",'S');
char returnVal,filtred;
string raw;
Plan plans[3];
switch(planType){
case 'H': plans = homePlans; break;
case 'B': plans = bisnuessPlans; break;
default: Error err(1,"getPlanSpeed","PlanType not H nor B")
}
while(true){
cout<<"(instruction at planspeed)"<<endl;
for (int i;i<3;i++){
cout<<plans[i].speed<<endl;
}
cout<<"(1/2/3)";
cin>>raw; filtred = raw[0]; //Get the first charactor
if(filtred == 'H'|filtred == 'B') {
returnVal = filtred;
break;
}
cout<<"(invalid option)"<<endl;
logToFile("Invalid option has been inputted, re-executing.",'W');
}
logToFile("End: Interface::getPlanSpeed()",'S');
return returnVal;
}
}
//main
int main(){
logFile<<"# S for standard log, E for Error, W for Warning"<<endl;
try{
logToFile("Initialized.",'S');
Interface::greetings();
planTypeSelected = Interface::getPlanType();
RETURN_CODE = 0;
}catch(Error e){
logToFile(e.getLogMsg(),'E');
RETURN_CODE = 1;
}
stringstream returnMessage;returnMessage << "Program exitted with code "<<RETURN_CODE;
logToFile(returnMessage.str(),'S');
return RETURN_CODE;
}