In: Computer Science
For C++
Download the attached program template.
The programs calculates the amount of profit or loss from a stock transaction. Using the values initialized by the program, calculate and print out the following results:
"Total paid for stock"
"Purchase commission "
"Total received for stock"
"Sales commission"
"Amount of profit or loss"
Use the following formulas:
Total_paid = (total purchase price) + purchase_commission;
Total_received = (total sales price) - sales_commission;
profit = Total_received - Total_paid
/* * COSC 1337 Programming Fundamentals II * Programming Assignment 1 * */ /* * File: main.cpp * Author: <student name> * * Created on August 7, 2019, 9:50 PM */ #include <iostream> #include <iomanip> using namespace std; int main() { const int NUM_SHARES = 100; // Number of shares of stock const double BUY_PRICE = 45.50, // Price per share when bought SELL_PRICE = 47.92, // Price per share when sold COMMISSION_PCT = .02; // % of buy or sell total paid to broker // Perform calculations for the purchase; // Perform calculations for the sale // Display results cout << fixed << setprecision(2); return 0; }
/* * COSC 1337 Programming Fundamentals II * Programming Assignment 1 * */ /* * File: main.cpp * Author: <student name> * * Created on August 7, 2019, 9:50 PM */ #include <iostream> #include <iomanip> using namespace std; int main() { const int NUM_SHARES = 100; // Number of shares of stock const double BUY_PRICE = 45.50, // Price per share when bought SELL_PRICE = 47.92, // Price per share when sold COMMISSION_PCT = .02; // % of buy or sell total paid to broker double purchase_commission, total_paid, sales_commission, total_received, profit; // Perform calculations for the purchase; purchase_commission = NUM_SHARES*BUY_PRICE*COMMISSION_PCT; total_paid = (NUM_SHARES*BUY_PRICE)+purchase_commission; // Perform calculations for the sale sales_commission = NUM_SHARES*SELL_PRICE*COMMISSION_PCT; total_received = (NUM_SHARES*SELL_PRICE)+sales_commission; profit = total_received - total_paid; // Display results cout << fixed << setprecision(2); cout<<"Total paid for stock: "<<total_paid<<endl; cout<<"Purchase commission: "<<purchase_commission<<endl; cout<<"Total received for stock: "<<total_received<<endl; cout<<"Sales commission: "<<sales_commission<<endl; cout<<"Amount of profit or loss: "<<profit<<endl; return 0; }