Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

need this c++ program with class constructor: #include #include using namespace std; void getInfo(string, double&); double profit(double, double, double, double, double); double inputValidate(double); void displayCalculation(double,

need this c++ program with class constructor:

#include #include

using namespace std;

void getInfo(string, double&); double profit(double, double, double, double, double); double inputValidate(double); void displayCalculation(double, int);

int main() { double NS, // Number of shares PP, // Purchase price per share PC, // Purchase commission paid SP, // Sale price per share SC, // Sale commission paid profit_or_loss, number_of_stock_sales, total = 0;

getInfo("How many stock sales? ", number_of_stock_sales);

for (int i = 0; i < number_of_stock_sales; i++) { cout << " Info for stock sale #" << (i + 1) << endl;

getInfo("Number of shares: ", NS); getInfo("Purchase price per share: ", PP); getInfo("Purchase commission paid: ", PC); getInfo("Sale price per share: ", SP); getInfo("Sale commission paid: ", SC);

profit_or_loss = profit(NS, PP, PC, SP, SC);

total += profit_or_loss;

displayCalculation(profit_or_loss, (i + 1)); }

cout << " Total profit or loss = $" << total << endl;

system("pause"); return 0; } // END int main()

void getInfo(string prompt, double& user_input) { cout << prompt; user_input = inputValidate(user_input); }

double inputValidate(double num1) {

while (!(cin >> num1) || num1 < 0) { cout << "Error. Number must not be " << " 0 or greater:"; cin.clear(); cin.ignore(numeric_limits::max(), ' '); }

return num1; }

double profit(double NS, double PP, double PC, double SP, double SC) { cout << "NS = " << NS << endl; cout << "PP = " << PP << endl; cout << "PC = " << PC << endl; cout << "SP = " << SP << endl; cout << "SC = " << SC << endl;

return ((NS * SP) - SC) - ((NS * PP) + PC); }

void displayCalculation(double profit_or_loss, int stock_number) { cout << "The sale of stock #" << stock_number << " resulted in " << (profit_or_loss < 0 ? "LOSS." : "PROFIT.") << "At $" << profit_or_loss << endl; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

More Books

Students also viewed these Databases questions

Question

3. Identify cultural universals in nonverbal communication.

Answered: 1 week ago

Question

2. Discuss the types of messages that are communicated nonverbally.

Answered: 1 week ago