• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 257
  • Last Modified:

UNDERSTANDING THE CODE

I am not understanding what is going on in this part of the program except I understand they declared a structure.  Could someone help me understand what this part of the code is doing?
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
#include <vector>
using namespace std;


enum Market {  INITIAL = -1, NYSE, AMEX, OTC, NASDAQ, NUM_MARKETS };

struct Share
{
    Market    market;
    int       shares;
    double    price;
   
    Share() : market(INITIAL), shares(0), price(0.0) {}
    Share(Market m, int s, double p) : market(m), shares(s), price(p) {}
};    

const char*  StockMarkets[NUM_MARKETS]   = { "NYSE", "AMEX", "OTC", "NASDAQ" };
double       CommissionFees[NUM_MARKETS] = { 0.02, 0.025, 0.03, 0.05 };

int main()
{
    char           Answer;
    vector<Share>  ShareArr;
    double         MarketValues[NUM_MARKETS] = { 0.00 };
0
mmorse0971
Asked:
mmorse0971
1 Solution
 
Jaime OlivaresCommented:
Well, share, as you can see, is your main data type

Share has 2 constructor functions:
- A default constructor, first one, doesn't require arguments, set member with default values
- Another constructor which receives values from creator of the object

there are 2 global arrays also: StockMarkets (array of strings) and CommissionFees (array of double floating point numbers)

Inside main:
vector<Share> ShareArr;  declares an empty dynamic array (called 'vector' instead of array) using STL library's vector template
also is declared another array of doubles (local): MarketValues
0
 
furqanchandioCommented:
hi

#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
************ Above code is include files and setting namespace **************

enum Market {  INITIAL = -1, NYSE, AMEX, OTC, NASDAQ, NUM_MARKETS };
in above statement initial= -1 , nyse=0, amex=1, otc=2, nasdaq=3,num_markets=4
**********************************


struct Share
{
    Market    market;
    int       shares;
    double    price;
   
    Share() : market(INITIAL), shares(0), price(0.0) {}
    Share(Market m, int s, double p) : market(m), shares(s), price(p) {}
};    
*********
** above setting up the structure with two constructors
first contructors takes no arguments and
setsmarket=-1
sharres=0 and price =0.0

second constructor takes three arguments

const char*  StockMarkets[NUM_MARKETS]   = { "NYSE", "AMEX", "OTC", "NASDAQ" };
*** above sets up a string initalsed with
StockMarket[0]="NYSE"
StockMarket[1]="AMEX"
....
StockMarket[3]="NASDAQ";


double       CommissionFees[NUM_MARKETS] = { 0.02, 0.025, 0.03, 0.05 };
***** above statement sets an array CommisionFees initialised with values
CommisionFess[0]=0.02
CommisionFess[1]=0.025
CommisionFess[2]=0.03
CommisionFess[4]=0.05

int main()
{
    char           Answer;
    vector<Share>  ShareArr;  sets up a vector  ( kind of a array of type share)


    double         MarketValues[NUM_MARKETS] = { 0.00 };
above MarketValues[4]=0.00  

cheers
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now