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 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
|
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
class Revenue
{
private:
string divName; //division name
string divNum; //divsion number
int numEmp; //number of employees
double ttlSales; //total sales
double ttlCosts; //total costs
double profit; //profit
double costPerEmp; //cost per employee
public:
static int numDivs; //number of divisions this one is static,
static int quarterNum; // quarter number this one also.
Revenue(); //Defualt constructor
string setdivName();
string getdivName()
{ return divName; }
string setdivNum();
string getdivNum()
{ return divNum; }
int setnumEmp();
int getnumEmp()
{return numEmp; }
double setttlSales();
double getttlSales()
{ return ttlSales; }
double setttlCosts();
double getttlCosts()
{ return ttlCosts; }
double setprofit(double ttlSales, double ttlCosts);
double getprofit()
{ return profit; }
double setcostPerEmp(double ttlCosts, double numEmp);
double getcostPerEmp()
{ return costPerEmp; }
static int setnumDivs();
static int getnumDivs()
{ return numDivs; }
static int setquarterNum();
static int getquarterNum()
{ return quarterNum; }
};
/******Defualt Constructor*********/
Revenue::Revenue()
{
ttlSales = ttlCosts = profit = costPerEmp = 0; divNum = numEmp = 0;
}
/***********Revenue::setdivName***************/
string Revenue::setdivName()
{
cout << "Type the division name.\n";
cin.ignore(100, '\n');
getline(cin, divName);
return ("string");
}
/***********Revenue::setdivNum****************/
string Revenue::setdivNum()
{
cout << "Enter the division number.\n";
cin >> divNum;
if(divNum.length() != 4)
{
do
{
cout << "The division number can only be 4 digits in length. Try again: \n";
cin >> divNum;
}
while(divNum.length() != 4);
}
return (divNum);
}
/**************Revenue::setnumEmp**************/
int Revenue::setnumEmp()
{
cout << "Enter the number of employees.\n";
cin >> numEmp;
return (numEmp);
}
/************Revenue::setttlSales*************/
double Revenue::setttlSales()
{
cout << "Input the total sales amount.\n";
cin >> ttlSales;
return (ttlSales);
}
/*************Revenue::setttlCosts************/
double Revenue::setttlCosts()
{
cout << "Input the total Costs amount.\n";
cin >> ttlCosts;
return (ttlCosts);
}
/************Revenue::setprofit********/
double Revenue::setprofit(double ttlSales, double ttlCosts)
{
profit = ttlSales - ttlCosts;
return (profit);
}
/*************Revenue::setcostPerEmp*********/
double Revenue::setcostPerEmp(double ttlCosts, double NumEmp)
{
costPerEmp = ttlCosts/numEmp;
return (costPerEmp);
}
/**********Revenue::setnumDivs**************/
int Revenue::setnumDivs()
{
cout << "How many Revenue records will you be inputing this session?\n";
cin >> Revenue::numDivs;
return (numDivs);
}
/**********Revenue::setquarterNum***********/
int Revenue::setquarterNum()
{
cout << "The information inputed into this program is for which quarter?." << endl;
cin >> quarterNum;
return (quarterNum);
}
/***************Initialize static variables*****************************/
int Revenue::numDivs = 0;
int Revenue::quarterNum = 0;
int desIntro();
int choice;
int main()
{
int num = 0;
Revenue ReV;
desIntro();
do
{
if(choice == 2)
{cout << "The program will now exit.\n";
return (0);
}
else if(choice == 1)
{break;}
else if(choice != 1 || choice != 2)
{ cout << " you did not enter a '1' or a '2', try again: \n";
cin >> choice;
}
}
while(choice != 1 || choice != 2);
ReV.setnumDivs();
do
{
ReV.setquarterNum();
ReV.setdivName();
ReV.setdivNum();
ReV.setnumEmp();
ReV.setttlSales();
ReV.setttlCosts();
ReV.setprofit(ReV.getttlSales(), ReV.getttlCosts());
ReV.setcostPerEmp(ReV.getttlCosts(), ReV.getttlSales());
cout << showpoint << fixed << setprecision(2);
cout << "Division Name: " << ReV.getdivName() << endl;
cout << "Division Number: " << ReV.getdivNum() << endl;
cout << "Quarter: " << ReV.getquarterNum() << endl;
cout << "Number of employees: " << ReV.getnumEmp() << endl;
cout << "Total Sales: " << ReV.getttlSales() << endl;
cout << "Cost per employee: " << ReV.getcostPerEmp() << endl;
cout << "Total Costs: " << ReV.getttlCosts() << endl;
cout << "Profit per quarter: " << ReV.getprofit() << endl;
Revenue* ReVA = new Revenue[Revenue::numDivs]; //intialize the dynamic array...yay..
ReVA[num].setdivName();
ReVA[num].setdivNum();
ReVA[num].setnumEmp();
ReVA[num].getttlSales();
ReVA[num].getttlCosts();
ReVA[num].getprofit();
ReVA[num].getcostPerEmp();
num++;
ofstream dMover;
dMover.setf(ios_base::fixed, ios_base::floatfield);
dMover.precision(2);
dMover.open("cop2224_proj2.xml", ios::out | ios::app);
dMover << "<?xml version='1.0' encoding='utf-8'?>\n";
dMover << "<revenue>\n";
for(int counter = 0; counter < num; counter++)
{
dMover << " <Division>\n";
dMover << " <DivisionName>" << ReVA[counter].getdivName() << "</DivisionName>\n";
dMover << " <DivisionNumber>" << ReVA[counter].getdivNum() << "</DivisionNumber>\n";
dMover << " <NumberofEmployees>" << ReVA[counter].getnumEmp() << "</NumberofEmployees>\n";
dMover << " <TotalSales>" << ReVA[counter].getttlSales() << "</TotalSales>\n";
dMover << " <TotalCosts>" << ReVA[counter].getttlCosts() << "</TotalCosts>\n";
dMover << " <Profit>" << ReVA[counter].getprofit() << "</profit>\n";
dMover << " <CostPerEmployee>" << ReVA[counter].getcostPerEmp() << "<CostPerEmployee>\n";
dMover << " <Division>\n";
dMover << " <Quarter>" << Revenue::quarterNum << "</Quarter>\n";
}
dMover << "</revenue>\n";
dMover.close();
cout << "===========================================================================\n";
cout << "Division record: " << num << " of " << Revenue::numDivs << " is complete.\n";
cout << "If you would you like to continue press '1' then the 'Enter' key. \n";
cout << "If you would like to quit, press '2' then the 'Enter' key.\n";
cin >> choice;
do
{
if(choice == 2)
{
cout << "The program will now exit.\n";
return (0);
}
else if(choice == 1)
{
break;
}
else if(choice != 1 || choice != 2)
{
cout << " you did not enter a '1' or '2', try again: \n";
cin >> choice;
}
}
while(choice != 1 || choice != 2);
}
while(num != Revenue::numDivs);
cout << "The records have been written to cop2224_proj2.xml\n";
cout << "The program will now shut down.\n";
return 0;
}
/***************description and introduction function****************/
int desIntro()
{
cout << "The purpose of this program is to calculate corporate revenue\n";
cout << "for a quarter of a business year.\n";
cout << "The program will store a set of Revenue objects in a dynamic\n";
cout << "array and output the values of each object to an XML file.\n";
cout << endl;
cout << "If you would like to continue press '1', then the 'Enter' key.\n";
cout << "If you would like to exit the program press '2', then the 'Enter' key\n";
cin >> choice;
return(0);
}
|