Question

In: Computer Science

Design a program (in C++)to calculate the stock purchasing and selling transactions. 1. ask the user...

Design a program (in C++)to calculate the stock purchasing and selling transactions.

1. ask the user to enter the name of the stock purchased, the number of share purchased, and the price per share purchased

2. assume the buyer pays 2% of the amount he paid for the stock purchase as broker commission

3. assume that the buyer sold all stocks. Ask the user to enter the price per share sold.

4. assume the buyer will pay another 2% of the amount he received for selling the stock as broker commission


the program will calculate and display:

1. the amount of money he paid for the stock purchase

2. the amount of commission he paid to the broker for purchase transaction

3. the amount he sold the stock for

4. the amount of commission he paid to the broker for purchase selling

5. the possible profit he made after selling his stock and paying the two commissions to the broker

Solutions

Expert Solution

Code:

#include <iostream>

#include<string>

int main() {

std::string stockBought;

int numberOfStocksBought;

double pricePerShareBought;

double pricePerShareSold;

double totalAmountInBuying;

double totalAmountInSelling;

// 1. ask the user to enter the name of the stock purchased, the number of share purchased, and the price per share purchased

std::cout << "Enter the name of the stock purchased: ";

std:: cin >> stockBought;

std::cout << "Enter the number of share purchased: ";

std:: cin >> numberOfStocksBought;

std::cout << "Enter the price per share bought: ";

std:: cin >> pricePerShareBought;

//2. assume the buyer pays 2% of the amount he paid for the stock purchase as broker commission; Total amount = amount spent in buying the stock + brokerage

totalAmountInBuying = (pricePerShareBought * numberOfStocksBought) +(0.02* pricePerShareBought * numberOfStocksBought) ;

//3. assume that the buyer sold all stocks. Ask the user to enter the price per share sold.

std::cout << "Enter the price per share sold: ";

std:: cin >> pricePerShareSold;

//4. assume the buyer will pay another 2% of the amount he received for selling the stock as broker commission; Total amount = amount received after selling the stock - brokerage

totalAmountInSelling = (pricePerShareSold * numberOfStocksBought)-(0.02* pricePerShareSold * numberOfStocksBought) ;

//Printing all the values

std::cout <<"The amount of money paid for the stock purchase: "<< (pricePerShareBought * numberOfStocksBought);

std::cout <<"\nThe amount of commission he paid to the broker for purchase transaction: "<< (0.02* pricePerShareBought * numberOfStocksBought);

std::cout <<"\nThe amount the stock was sold: "<<(pricePerShareSold * numberOfStocksBought);

std::cout <<"\nThe amount of commission paid to the broker for purchase selling: "<<(0.02* pricePerShareSold * numberOfStocksBought);

std::cout <<"\nThe profit made after selling his stock and paying the two commissions to the broker: "<<totalAmountInSelling - totalAmountInBuying;

}

Output:

Please do hit a like if you find my answer satisfactory!!


Related Solutions

In C++ Design a program to calculate the stock purchasing and selling transactions. 1. ask the...
In C++ Design a program to calculate the stock purchasing and selling transactions. 1. ask the user to enter the name of the stock purchased, the number of share purchased, and the price per share purchased 2. assume the buyer pays 2% of the amount he paid for the stock purchase as broker commission 3. assume that the buyer sold all stocks. Ask the user to enter the price per share sold. 4. assume the buyer will pay another 2%...
Design a program that will ask the user to input two integer numbers and then perform...
Design a program that will ask the user to input two integer numbers and then perform the basic arithmetic operations such as addition and subtraction. Each calculation is done by a separate function. The main function gets the input from the user, then calls the addition function and the subtraction function one at a time to perform the calculations. Each calculation function (addition or subtraction function) performs an arithmetic operation and then returns the calculation results back to where it...
C LANGUAGE Ask user how many scores there are, then ask for each score. Then calculate...
C LANGUAGE Ask user how many scores there are, then ask for each score. Then calculate the average score and scores below 60. Then display the average score and number of scores below 60
C++ In this lab, you will ask the user to design a leaning pyramid. The pyramid...
C++ In this lab, you will ask the user to design a leaning pyramid. The pyramid will either lean left or right. Start by asking the user how tall they want the pyramid to be. Then ask the user if they want the pyramid to lean left or right. You should then display a pyramid that meets the requirements. (See below for examples). YOU MUST use nested loops for your solution for ANY credit. Sample Run #1: Enter a pyramid...
Create a C++ program that will ask the user for how many test scores will be...
Create a C++ program that will ask the user for how many test scores will be entered. Setup a while loop with this loop iteration parameter. (no fstream) The data needs to include the student’s first name, student number test score the fields should be displayed with a total width of 15. The prompt should be printed with a header in the file explaining what each is: ex. First Name student number Test Score 1) mike 6456464   98 2) phill...
Write a program in C, that uses standard input and output to ask the user to...
Write a program in C, that uses standard input and output to ask the user to enter a sentence of up to 50 characters, the ask the user for a number between 1 & 10. Count the number of characters in the sentence and multiple the number of characters by the input number and print out the answer. Code so far: char sentence[50]; int count = 0; int c; printf("\nEnter a sentence: "); fgets(sentence, 50, stdin); sscanf(sentence, %s;    for(c=0;...
Implement a program in C++ that does the following: Ask the user and read at least...
Implement a program in C++ that does the following: Ask the user and read at least 10 numbers as input from the keyboard and stores them in a an array Displays the array of numbers on the screen (as is, before sorting) Sorts those numbers in the array using Selection Sort Algorithm Displays the array of numbers on the screen (AFTER sorting)
Ask the user to input a series of numbers, write a C# program to output the...
Ask the user to input a series of numbers, write a C# program to output the sum, max, and min. Be sure to do error checking if the user input is not a number.
c++ In this program ask the user what name they prefer for their file, and make...
c++ In this program ask the user what name they prefer for their file, and make a file, the file name should za file. Get a number from the user and save it into the create file. should be more than 20 number in any order. print out all 20 numbers in a sorted array by using for loop, last print out its total and average. At last create a function in which you will call it from main and...
c++ Write a program that will ask the user for three pairs of integer values. The...
c++ Write a program that will ask the user for three pairs of integer values. The program will then display whether the first number of the pair is multiple of the second. The actual work of making the determination will be performed by a function called IsMultiple that takes two integer arguments (say, x and y). The function will return a Boolean result of whether x is a multiple of y.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT