Starting from:
$30

$24

STOCK QUOTES HOMEWORK 1 SOLUTION

 Write a C# console application (or windows application for extra credit) to calculate the from profit the sale of a stock according to the following formula: 
profit = ((NS* SP) - SC) - (NS * PP) + PC) 

NS: number of shares 
SP: sale price per share 
SC: Sale commission paid 
PP: purchase price per share 
PC: Purchase commission paid 
If the calculation results in positive value then the sale of the stock result in a profit, if negative it means loss. 
On your submission make sure to include 
//student name: Your name 
//Date: 
//Name of hw: HW#1: stock quotes 
The code in C++ is as follow: 
// Stock Profit 
#include <iostream> 
#include <iomanip> 
using namespace std; 
// Function prototype 
double profit(double, double, double, double, double); 
int main() 

int ns; // Number of shares 
double sp; // Sale price per share 
double sc; // Sale commission 
double pp; // Purchase price per share 
double pc; // Purchase commission 
double prof; // Profit from a sale 
// Get the number of shares. 
cout << "How many shares did you buy and then sell? "; 
cin >> ns; 
// Get the purchase price per share. 
cout << "What price did you pay for the stock " 
<< "per share? "; 
cin >> pp; 
// Get the purchase commission. 
cout << "What was the purchase commission? "; 
cin >> pc; 
// Get the sale price per share. 
cout << "What was the sale price per share? "; 
cin >> sp; 
// Get the sales commission. 
cout << "What was the sales commission? "; 
cin >> sc; 
// Get the profit or loss. 
prof = profit(ns, pp, pc, sp, sc); 
// Display the result. 
cout << "The profit from this sale of stock is $" 
<< setprecision(2) << fixed << showpoint 
<< prof << endl; 
return 0; 

// ******************************************************** 
// The profit function accepts as arguments the number of * 
// shares, the purchase price per share, the purchase * 
// commission paid, the sale price per share, and the * 
// sale commission paid. The function returns the profit * 
// (or loss) from the sale of stock as a double. * 
// ******************************************************** 
double profit(double ns, double pp, double pc, 
double sp, double sc) 

return ((ns * sp) - sc) - ((ns * pp) + pc); 

Sample I/O in c++

More products