Question

6.3 Lab Lesson 3 (Part 3 of 3) Part of lab lesson 3 There are three...

6.3 Lab Lesson 3 (Part 3 of 3) Part of lab lesson 3 There are three parts to lab lesson 3. The entire lab will be worth 100 points. Bonus points for lab lesson 3 There are also 10 bonus points. To earn the bonus points you have to complete the Participation Activities and Challenge Activities for zyBooks/zyLabs unit 5 (Gaddis Chapter 3). These have to be completed by the due date for lab lesson 3. For example, if you complete 89% of the activities you will get 8 points (there is no rounding). As with units 1 and 2 the bonus points on zyBooks will be more than 10 points. These will adjust to 10 points total for the bonus points on the grade in eLearning. This will be true for the units that map to Gaddis Chapters 3 through 7. Lab lesson 3 part 3 is worth 40 points For part 3 you will have 30 points if you enter the program and successfully run the program tests. An additional 10 points will be based on the style and formatting of your C++ code. Style points The 10 points for coding style will be based on the following guidelines: Comments at the start of your programming with a brief description of the purpose of the program. Comments throughout your program Proper formatting of your code (follow the guidelines in the Gaddis text book, or those used by your CS 1336 professor) If you have any variables they must have meaningful names. Development in zyBooks For lab lesson 3 (all parts) you will be entering your programs directly into zyBooks/zyLabs. If you want to use an Integrated Development Environment (IDE) such as Visual Studio, Code::Blocks or Eclipse you can do so, but you will have to cut and paste the code into zyBooks/zyLabs. You will need to use Develop mode and Submit mode as you did in lab lessons 1 and 2. Staring with lab lesson 4 you will be doing your development in an IDE (use whatever your CS 1336 class is using) and you will be uploading the files to zyBooks/zyLabs. C++ requirements The commission percentage (see below) must be put into a const double variable that you will use in your calculations. The numeric variables in your program need to be of type double. You will have to use getline to read in the company name since it can include spaces. You must use the string class for the company name you read in from the user. Failure to follow the C++ requirements could reduce the points received from passing the tests. General overview Display a prompt for the user telling them to enter in the name of the company. The prompt is: Enter the name of the company Read in the name of the company into a string. You must use getline to read in the company name since the company name may have spaces in the name. Next prompt for the number of shares of stock with the prompt: Enter shares of stock Now read in the number of shares of stock. This is of type int. Prompt for the purchase price with the prompt: Enter purchase price Read the purchase price into a variable of type double. Now prompt for the sale price for the stock with the prompt: Enter sale price Finally read in the stock sale prices. This is also of type double. Output a blank line before you output any result from the following calculations. Now that you have read in the data you can calculate the total amount required to purchase the stock. You also need to calculate the commission that has to be paid to the stockbroker. The stockbroker commission will be 3.5% of the amount required to purchase the stock. Note: the commission percentage must be put into a const double variable that you will use in your calculations. The numeric variables in your program need to be of type double. Output the name of the company, the cost of a share of stock, the total amount required to pay for the stock (not including the commission), the commission, and the total cost of the stock (including the commission). Next calculate the amount of income you will get when you sell the stock for the stock sales price. You also need to calculate the cost of the commission to the stockbroker for the sale of the stock. Again this will be 3.5% of the money you get for selling the stock. Output the price of one share of stock, the amount of money you get from the sale (before the commission is paid), the amount of the commission, and the amount of money you get from the sale after you have paid the commission to the stockbroker. All of the money amounts should be output in a fixed format with two digits to the right of the decimal point. Final calculate the difference between what you paid for the stock (including the commission), and what you received when you sold the stock (less the commission). This number will be negative if you have lost money. Here is some sample input data: Acme Software, Inc. 1000 45.50 56.90 The output from the above input will be: Company: Acme Software, Inc. Shares: 1000 Purchase/share: $45.50 Cost of stock: $45500.00 Cost of commission: $1592.50 Total cost: $47092.50 Sale/share: $56.90 Income from stock: $56900.00 Cost of commission: $1991.50 Total income: $54908.50 Gain or loss: $7816.00 Failure to follow the requirements for lab lessons can result in deductions to your points, even if you pass the validation tests. Logic errors, where you are not actually implementing the correct behavior, can result in reductions even if the test cases happen to return valid answers. This will be true for this and all future lab lessons.

Homework Answers

Answer #1

// C++ program to calculate the gain or loss obtained by purchase and sale of given number of stock

#include <iostream>

#include <string>

#include <iomanip>

using namespace std;

int main() {

       string company;

       const double commissionPercent = 3.5; // commission percentage constant

       double purchasePrice, salePrice, commissionPurchase, commissionSale;

       int num_shares;

       double totalPurchasePrice, totalSalePrice, result;

       // input of company name

       cout<<"Enter the name of the company : ";

       getline(cin,company);

       company = company.substr(0,company.length()-1); // remove '\n' from the end

       // input of number of shares

       cout<<"Enter shares of stock : ";

       cin>>num_shares;

       // input of purchase price

       cout<<"Enter purchase price : ";

       cin>>purchasePrice;

       // input of sale price

       cout<<"Enter sale price : ";

       cin>>salePrice;

       cout<<endl;

       // calculate total purchase price without commission

       totalPurchasePrice = num_shares*purchasePrice;

       // calculate commission on the purchase of shares

       commissionPurchase = (totalPurchasePrice*commissionPercent)/100;

       // calculate total sale price without commission

       totalSalePrice = num_shares*salePrice;

       // calculate commission on the sale price

       commissionSale = (totalSalePrice*commissionPercent)/100;

       // calculate the profit or loss by subtracting the total sale price by total purchase price

       // total sale price = total sale before commission - sale commission

       // total purchase price = total purchase before commission + sale commission

       result = (totalSalePrice-commissionSale)-(totalPurchasePrice+commissionPurchase);

       // output the result

       cout<<fixed<<setprecision(2);

       cout<<"Company : "<<company<<endl;

       cout<<"Shares : "<<num_shares<<endl;

       cout<<"Purchase/share: $"<<purchasePrice<<endl;

       cout<<"Cost of stock: $"<<totalPurchasePrice<<endl;

       cout<<"Cost of commission: $"<<commissionPurchase<<endl;

       cout<<"Total cost: $"<<(totalPurchasePrice+commissionPurchase)<<endl;

       cout<<"Sale/share: $"<<salePrice<<endl;

       cout<<"Income from stock: $"<<totalSalePrice<<endl;

       cout<<"Cost of commission: $"<<commissionSale<<endl;

       cout<<"Total income: $"<<(totalSalePrice-commissionSale)<<endl;

       cout<<"Gain or loss: $"<<result<<endl;

       return 0;

}

//end of program

Output:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
WRITE A JAVA PROGRAM 1. Assignment Description Write a stock transaction program that calculates a customer's...
WRITE A JAVA PROGRAM 1. Assignment Description Write a stock transaction program that calculates a customer's profit (or loss) within a certain period of time. 1) First, the program need to get user's name, the stock's code, number of shares and the price he/she purchased the stock, it also asks the user for the price he/she sold the stock later on. The program then compute the following: The amount of money the customer paid for the stock. The amount of...
n this lab, you use what you have learned about parallel arrays to complete a partially...
n this lab, you use what you have learned about parallel arrays to complete a partially completed C++ program. The program should: Either print the name and price for a coffee add-in from the Jumpin’ Jive Coffee Shop Or it should print the message Sorry, we do not carry that. Read the problem description carefully before you begin. The file provided for this lab includes the necessary variable declarations and input statements. You need to write the part of the...
Write a C program that allows the user to balance a credit card account. The program...
Write a C program that allows the user to balance a credit card account. The program should first prompt the user to enter the Bank Name, and the beginning balance of his/her credit card account (must allow for dollars and cents). The program should then prompt the user to enter the number of refunds to be posted, and then the number of payments to be posted, and then the number of charges to be posted. For this assignment, let's set...
I need this before the end of the day please :) In Java 10.13 Lab 10...
I need this before the end of the day please :) In Java 10.13 Lab 10 Lab 10 This program reads times of runners in a race from a file and puts them into an array. It then displays how many people ran the race, it lists all of the times, and if finds the average time and the fastest time. In BlueJ create a project called Lab10 Create a class called Main Delete what is in the class you...
I. General Description In this assignment, you will create a Java program to read undergraduate and...
I. General Description In this assignment, you will create a Java program to read undergraduate and graduate students from an input file, sort them, and write them to an output file. This assignment is a follow up of assignment 5. Like assignment 5, your program will read from an input file and write to an output file. The input file name and the output file name are passed in as the first and second arguments at command line, respectively. Unlike...
JAVA public class Purchase { private String name; private int groupCount; //Part of price, like the...
JAVA public class Purchase { private String name; private int groupCount; //Part of price, like the 2 in 2 for $1.99. private double groupPrice; //Part of price, like the $1.99 in 2 for $1.99. private int numberBought; //Total number being purchased. public Purchase () { name = "no name"; groupCount = 0; groupPrice = 0; numberBought = 0; } public Purchase (String name, int groupCount, double groupPrice, int numberBought) { this.name = name; this.groupCount = groupCount; this.groupPrice = groupPrice; this.numberBought...
Write a C++ program. 1) Write a program that writes the grades for 3 students. Declare...
Write a C++ program. 1) Write a program that writes the grades for 3 students. Declare a variable of type ofstream which is used to output a stream into a file: ofstream output; // output is the name of the variable Prompt the user to input values for the grades of 3 students. Use the output operator (<<) to write the grades into grades.txt: output << grade1 << " " << grade2 << " " << grade3 << endl; You...
In C programming, Thank you Write a program to compute the area of a circle. You...
In C programming, Thank you Write a program to compute the area of a circle. You have to write a complete “C” program that compiles and runs in Codeblocks. Program requirements: 1. Declare the variables needed: radius (r) and area (yourLastName). 2. Calculate and print the area of each circle. 3. The program MUST prompt the user for a new radius (r) over and over until the user types -1. 5. Use the type double for all decimal numbers. 6....
For PYTHON program you will be writing a program that will use if-else or if-elif-else statements....
For PYTHON program you will be writing a program that will use if-else or if-elif-else statements. Read-It-All bookstore has a book sales club where customers can earn reward points that can be used for their next purchase. If a customer purchases 0 books, he/she earns 0 points. If a customer purchases 1-3 books, he/she earns 5 points. If a customer purchases 4-6 books, he/she earns 10 points. If a customer purchases 7-8 books, he/she earns 15 points. If a customer...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in Lab 2 to obtain a diameter value from the user and compute the volume of a sphere (we assumed that to be the shape of a balloon) in a new program, and implement the following restriction on the user’s input: the user should enter a value for the diameter which is at least 8 inches but not larger than 60 inches. Using an if-else...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT