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
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,...
a.Create the logic for a program using pseudocode that calculates and displays the amount of money...
a.Create the logic for a program using pseudocode that calculates and displays the amount of money you would have if you invested $5000 at 2 percent simple interest for one year. Create a separate method to do the calculation and return the result to be displayed. b.Modify the program in Exercise 2a so that the main program prompts the user for the amount of money and passes it to the interest-calculating method. c.Modify the program in Exercise 2b so that...
Write a C program that calculates a student grade in the C Programming Class. Ask the...
Write a C program that calculates a student grade in the C Programming Class. Ask the user to enter the grades for each one of the assignments completed in class: Quiz #1 - 25 points Quiz #2 - 50 points Quiz #3 - 30 points Project #1 - 100 points Project #2 - 100 points Final Test - 100 points The total of the quizzes count for a 30% of the total grade, the total of the projects counts for...
C# CODE C# 1) Write a program that calculates a student's GPA. Remember, an A is...
C# CODE C# 1) Write a program that calculates a student's GPA. Remember, an A is worth 4 points, a B is worth 3 points, a C is worth 2 points, a D is worth 1 point, and an F is worth 0 points. For the purposes of this assignment, assume that all classes carry the same number of credit hours. 2) Use a sentinel-controlled loop to gather a variable number of letter grades. This should terminate the loop if...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT