-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.cpp
More file actions
executable file
·127 lines (116 loc) · 3.19 KB
/
Test.cpp
File metadata and controls
executable file
·127 lines (116 loc) · 3.19 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
//
// Test.cpp
// Test CPP file of main function
// Description : Main function Implementation
// Created by Swasti Gupta on 5/31/15.
#include "GBookStore.h"
#include "Base.h"
#include "CmdLineParser.h"
#include <sstream>
/*
Description Main function
*/
int main(int argc, const char * argv[])
{
if(argc != 7 && argc != 9)
{
return GParamError;
}
GStatus status;
CmdLineParser cmdParse; //Parser for Command Line Arguments
//checking for option t exits otherwise return parameter error
if(!cmdParse.cmdOptionExists((char**)argv, (char**)argv+argc, "t"))
{
return GParamError;
}
//checking for option p exits otherwise return parameter error
if(!cmdParse.cmdOptionExists((char**)argv, (char**)argv+argc, "p"))
{
return GParamError;
}
//checking for option r, d, c exits otherwise return parameter error
if(!cmdParse.cmdOptionExists((char**)argv, (char**)argv+argc, "r") &&
(!cmdParse.cmdOptionExists((char**)argv, (char**)argv+argc, "d")
||!cmdParse.cmdOptionExists((char**)argv, (char**)argv+argc, "c") ))
{
return GParamError;
}
//getting the TransactionList file path
char *fileTransaction = cmdParse.getCmdOption((char**)argv, (char**)argv + argc, "t");
if( fileTransaction == NULL)
{
return GParamError;
}
//getting the PriceList file path
char *filePrice = cmdParse.getCmdOption((char**)argv, (char**)argv + argc, "p");
if( filePrice == NULL)
{
return GParamError;
}
GBookStore b;// Object of GStore
if(cmdParse.cmdOptionExists((char**)argv, (char**)argv+argc, "r"))
{
//getting the value of N
char *nValue = cmdParse.getCmdOption((char**)argv,(char**)argv + argc, "r");
if( nValue == NULL)
{
return GParamError;
}
status = b.readPriceList(filePrice); //reading the priceList file.
if(status != GSuccess)
{
return status;
}
status = b.readTransactionList(fileTransaction); //reading the transactionList file.
if(status != GSuccess)
{
return status;
}
status = b.getNValues(atoi(nValue)); // getting top K Transation, top K Customers, top and bottom Books
if(status != GSuccess)
{
return status;
}
}
else
{
//getting the value of sum upto whic discount is given or not
char *discountValue = cmdParse.getCmdOption((char**)argv,(char**)argv + argc, "d");
if( discountValue == NULL || stod(discountValue) <= 0)
{
return GParamError;
}
//getting the CustmerId
char *custId = cmdParse.getCmdOption((char**)argv,(char**)argv + argc, "c");
if( custId == NULL || custId[0] != 'C')
{
return GParamError;
}
status = b.readPriceList(filePrice); //reading the priceList file.
if(status != GSuccess)
{
return status;
}
status = b.readTransactionList(fileTransaction); //reading the transactionList file.
if(status != GSuccess)
{
return status;
}
int discount = 0;
//calculating the state of providing discount
status = b.isDiscount(custId,stod(discountValue),&discount);
if(status != GSuccess)
{
return status;
}
if(discount)
{
cout<<endl<<"1"<<endl;
}
else
{
cout<<endl<<"0"<<endl;
}
}
return GSuccess;
}