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

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
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.
In C: Write a complete program that performs the following task: Ask the user for the...
In C: Write a complete program that performs the following task: Ask the user for the number of sequences to display. For each sequence, Ask the user for a starting value Print out the value and double it (multiply by 2). Continue printing and doubling (all on the same line, separated by one space each) as long as the current number is less than 1000, or until 8 numbers have been printed on the line. You may assume that the...
A, B:   Design and Implement a C# windows form application to ask the user for 10...
A, B:   Design and Implement a C# windows form application to ask the user for 10 integer numbers, sort them in ascending order and display the sorted list. Use bubble sort technique to sort the array elements and do not use any built-in sort method to sort the array elements.                                                        [02] C:    Test and evaluate your program by inputting variety of values.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT