Question

In: Computer Science

For C++ Download the attached program template. The programs calculates the amount of profit or loss...

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;
}

Solutions

Expert Solution

/*
 * 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;
}


Related Solutions

Lab 11 C++ Download the attached program and run it - as is. It will prompt...
Lab 11 C++ Download the attached program and run it - as is. It will prompt for a Fibonacci number then calculate the result using a recursive algorithm. Enter a number less then 40 unless you want to wait for a very long time. Find a number that takes between 10 and 20 seconds. (10,000 - 20,000 milliseconds). Modify the program to use the static array of values to "remember" previous results. Then when the function is called again with...
Your task is to write a program in C or C++ that calculates the total amount...
Your task is to write a program in C or C++ that calculates the total amount of money a person has made over the last year. Your program will prompt the user for dollar amounts showing how much the user has made per job. Some users will have had more than one job, make sure your program allows for this. The program will print out the total made (all jobs) and will print out the federal and state taxes based...
C++ Download the attached program and complete the functions. (Refer to comments) main.cpp ~ #include #include...
C++ Download the attached program and complete the functions. (Refer to comments) main.cpp ~ #include #include #define END_OF_LIST -999 using namespace std; /* * */ int exercise_1() { int x = 100; int *ptr; // Assign the pointer variable, ptr, to the address of x. Then print out // the 'value' of x and the 'address' of x. (See Program 10-2) return 0; } int exercise_2() { int x = 100; int *ptr; // Assign ptr to the address of...
make a c++ program that calculates the amount left from a value of money of one...
make a c++ program that calculates the amount left from a value of money of one dollar bill or less in quarters, dimes, nickels, and pennies. The remaining value can be shown in cents knowing that in cents: penny = 1 nickel = 5 dime = 10 quarter = 25
Design a c++ program that calculates the amount of money a person would earn over a...
Design a c++ program that calculates the amount of money a person would earn over a period of time if his salary is one penny the first day, two pennies second day, and continues to double each day. The program should ask the user for the number of days. Display a table showing what the salary was for each day, and then show total pay at the end of the period. the output should be displayed in a dollar amount,...
In C++ Complete the template program. ADD to your c++ program as a comment the PARTIAL...
In C++ Complete the template program. ADD to your c++ program as a comment the PARTIAL output from executing your program - Only copy the last 6 lines of output. There is no input data for this problem. // Find Pythagorean triples using brute force computing. #include <iostream> using std::cout; using std::endl; int main() { int count = 0; // number of triples found long int hypotenuseSquared; // hypotenuse squared long int sidesSquared; // sum of squares of sides cout...
Write pseudocode algorithms for the programs described as follows:- Available Credits A program that calculates a...
Write pseudocode algorithms for the programs described as follows:- Available Credits A program that calculates a customer’s available credit should as the user for the following:  The customers maximum amount of credit  The amount of credit used by the customer Once these items have been entered, the program should calculate and display the customer’s available credit. You can calculate available credit by subtracting the amount of the credit used from the maximum amount of credit. (I need this...
In C Program #include Create a C program that calculates the gross and net pay given...
In C Program #include Create a C program that calculates the gross and net pay given a user-specified number of hours worked, at minimum wage. The program should compile without any errors or warnings (e.g., syntax errors) The program should not contain logical errors such as subtracting values when you meant to add (e.g., logical errors) The program should not crash when running (e.g., runtime errors) When you run the program, the output should look like this: Hours per Week:...
1) Here is a program in c++ that calculates a speeding ticket, modify the program to...
1) Here is a program in c++ that calculates a speeding ticket, modify the program to double to cost of the ticket in a construction zone. // This project will calculate a speeding ticket between 0 to 150 mph. // 1. Ask for speed. // 2. Input speed of vehicle // 3. Calculate ticket cost (50$ if over 50mph with an additional 5$ for every mph over). // 4. Display cost of ticket. #include<iostream> using namespace std; int main() {...
Modify the provided code to create a program that calculates the amount of change given to...
Modify the provided code to create a program that calculates the amount of change given to a customer based on their total. The program prompts the user to enter an item choice, quantity, and payment amount. Use three functions: • bool isValidChoice(char) – Takes the user choice as an argument, and returns true if it is a valid selection. Otherwise it returns false. • float calcTotal(int, float) – Takes the item cost and the quantity as arguments. Calculates the subtotal,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT