# Question & Answer: I need help to complete this assignment below as per c+++, Please i will be glad if you could code and run…..

I need help to complete this assignment below as per c+++, Please i will be glad if you could code and run the program A. and B below separatly for me to see . Any modification besides the authur’s procedure is welcome. Thank you

Source: C++ PROGRAMMING (Program Design Including Data Structure (7th Edition) by D.S.Malik.

Don't use plagiarized sources. Get Your Custom Essay on
Question & Answer: I need help to complete this assignment below as per c+++, Please i will be glad if you could code and run…..
GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS \$13/PAGE

Programming Exercise 18

Minimum Requirements

You must provide a Word-style document explaining what your program does showing the expected runtime output.  Please advise me as to anything else that’s of importance to running it.

The company invests only in the stock market. At the end of each trading day, the company would like to generate and post the listing of its stocks so that investors can see how their holdings performed that day. We assume that the company invests in, say, 10 different stocks.

The desired output is to produce two listings,

one sorted by stock symbol and

another sorted by percent gain from highest to lowest.

The input data is provided in a file in the following format:
symbol openingPrice closingPrice todayHigh todayLow prevClose volume

For example, the sample data is:
MSMT 112.50 115.75 116.50 111.75 113.50 6723823
CBA 67.50 75.50 78.75 67.50 65.75 378233
The first line indicates that the stock symbol is MSMT, today’s opening price was 112.50, the closing price was 115.75, today’s high price was 116.50, today’s low price was 111.75, yesterday’s closing price was 113.50, and the number of shares currently being held is 6723823
The listing sorted by stock symbols must be of the following form:

Financial report

 STOCK SYMBOL ………….. OPEN ………… CLOSE ……….. HIGH ………. LOW ……….. PREVIOUS CLOSE ………… PERCENT GAIN ………… VOLUME …………… ABC 123.45 130.95 132.00 125.00 120.50 8.67% 10000 AOLK 80.00 75.00 82.00 74.00 83.00 -9.64% 5000 CSCO 100.00 102.00 105.00 98.00 101.00 0.99% 25000 IBD 68.00 71.00 72.00 67.00 75.00 -5.33% 15000 MSET 120.00 140.00 145.00 140.00 115.00 21.74% 30920

Develop this programming exercise in two steps:

A.

Design and implement a stock object. The main components of a stock are the stock symbol, stock price, and number of shares. Moreover, we need to output the opening price, closing price, high price, low price, previous price, and the percent gain/loss for the day. These are also all the characteristics of a stock. Therefore, the stock object should store all this information.
Perform the following operations on each stock object:
1. Set the stock information.
2. Print the stock information.
3. Show the different prices.
4. Calculate and print the percent gain/loss.
5. Show the number of shares.

B.

Design and implement an object to maintain a list of stocks.

Code :

A.

#include<iostream>

#include<iomanip>

#include<fstream>

using namespace std;

class stock{

public :

string symbol;

float openingPrice, closingPrice, todayHigh, todayLow, prevClose;

long volume;

stock(){}

stock (string symbol, float openingPrice, float closingPrice, float todayHigh, float todayLow, float prevClose, long volume){

this->symbol = symbol;

this->openingPrice = openingPrice;

this->closingPrice = closingPrice;

this->todayHigh = todayHigh;

this->todayLow = todayLow;

this->prevClose = prevClose;

this->volume = volume;

}

void display(){

cout<<setw(13)<<symbol;

cout<<setw(10)<<setprecision(10)<<openingPrice;

cout<<setw(10)<<setprecision(10)<<closingPrice;

cout<<setw(10)<<setprecision(10)<<todayHigh;

cout<<setw(10)<<setprecision(10)<<todayLow;

cout<<setw(15)<<setprecision(10)<<prevClose;

cout<<setw(10)<<volume<<endl;

}

void differentPrices(){

cout<<“symbol : “<<symbol<<endl;

cout<<“openingPrice : “<<openingPrice<<endl;

cout<<“closingPrice : “<<closingPrice<<endl;

cout<<“todayHigh : “<<todayHigh<<endl;

cout<<“todayLow : “<<todayLow<<endl;

cout<<“prevClose : “<<prevClose<<endl;

}

void percentGain(){

float gain = ((closingPrice-prevClose)/prevClose)*100;

cout<<“Percent Gain for “<<symbol<<” is “<<gain<<endl;

}

void showShares(){

cout<<“Number of shares of “<<symbol<<” is “<<volume<<endl;

}

};

int main()

{

stock s[10];

int count = 0;

ifstream fin;

fin.open(“stocks.txt”);

if (!fin) {

cerr << “Error in opening the file” << endl;

return 1;

}

while(!fin.eof())

{

fin>>s[count].symbol>>s[count].openingPrice>>s[count].closingPrice>>s[count].todayHigh>>s[count].todayLow>>s[count].prevClose>>s[count].volume;

count++;

}

cout<<setw(13)<<“STOCK SYMBOL”<<setw(10)<<“OPEN”<<setw(10)<<“CLOSE”<<setw(10)<<“HIGH”<<setw(10)<<“LOW”<<setw(15)<<“PREVIOUS CLOSE”<<setw(10)<<“VOLUME”<<endl;

for(int i=0; i<count; i++)

s[i].display();

cout<<endl;

for(int i=0; i<count; i++)

s[i].percentGain();

cout<<endl;

for(int i=0; i<count; i++)

s[i].showShares();

return 0;

}

Output :

B.

#include<iostream>

#include<iomanip>

#include<fstream>

#include<string>

using namespace std;

class stock{

public :

string symbol;

float openingPrice, closingPrice, todayHigh, todayLow, prevClose;

long volume;

stock(){}

stock (string symbol, float openingPrice, float closingPrice, float todayHigh, float todayLow, float prevClose, long volume){

this->symbol = symbol;

this->openingPrice = openingPrice;

this->closingPrice = closingPrice;

this->todayHigh = todayHigh;

this->todayLow = todayLow;

this->prevClose = prevClose;

this->volume = volume;

}

void display(){

cout<<setw(13)<<symbol;

differentPrices();

percentGain();

showShares();

}

void differentPrices(){

cout<<setw(10)<<setprecision(10)<<openingPrice;

cout<<setw(10)<<setprecision(10)<<closingPrice;

cout<<setw(10)<<setprecision(10)<<todayHigh;

cout<<setw(10)<<setprecision(10)<<todayLow;

cout<<setw(15)<<setprecision(10)<<prevClose;

}

void percentGain(){

float gain = ((closingPrice-prevClose)/prevClose)*100;

cout<<setw(13)<<setprecision(10)<<gain;

}

void showShares(){

cout<<setw(10)<<volume<<endl;

}

};

class stocklist{

public :

stock s[10];

stocklist()

{

int count = 0;

ifstream fin;

fin.open(“stocks.txt”);

if (!fin) {

cerr << “Error in opening the file” << endl;

}

while(!fin.eof())

{

fin>>s[count].symbol>>s[count].openingPrice>>s[count].closingPrice>>s[count].todayHigh>>s[count].todayLow>>s[count].prevClose>>s[count].volume;

count++;

}

}

void display()

{

int len = sizeof(s)/sizeof(s[0]);

for(int i=0; i<len; i++)

if(s[i].symbol.length() == 0)

break;

else

s[i].display();

}

};

int main()

{

stocklist sl;

cout<<setw(13)<<“STOCK SYMBOL”<<setw(10)<<“OPEN”<<setw(10)<<“CLOSE”<<setw(10)<<“HIGH”<<setw(10)<<“LOW”<<setw(15)<<“PREVIOUS CLOSE”<<setw(13)<<“PERCENT GAIN”<<setw(10)<<“VOLUME”<<endl;

sl.display();

}

Output: