1. Objective - University of Arkansas



Assignment 3 – Friday, Feb. 19, 2021 at 11:59pmThis assignment must be done individually.1. ObjectiveIn this assignment, we will be using our knowledge of loops to simulate investing in the stock market. The program will allow the user to select stocks to buy, and print out their portfolio after a period of time. Assignment 3 is designed to familiarize students with the three types of loops – while loops, for loops, and do while loops.2. DescriptionFarmer Jessie has decided to explore a new career. He already has a thriving pumpkin patch, and during his spring break, he heard that stocks were being sold for record high prices! Let’s help Farmer Jessie choose which stocks to buy and show him his final portfolio after three years.Part 1For the first part of this assignment, we are choosing which stocks to buy. You will give the user a certain amount of cash and a choice of at least four stocks to pick between. Similar to the last assignment, you can use a switch statement to create a menu for your options. Use a do while loop to allow the user to choose the stock, and buy a single share. Our stock market only handles whole dollar amounts, and the user can only buy one share of stock at a time,When the user has chosen which stock to buy, you need to check to make sure that they have enough cash to buy a single share. If not, display an error message. When they buy a stock, be sure to update the number of shares of the stock they own and the amount of cash they have on hand.In this assignment, you will be responsible for error handling for the expected input types. You do not need to check if a user enters a string instead of an integer, but you will need to use while loops and if statements to ensure the user enters a valid choice, and doesn’t attempt to spend more money than they currently have.Part 2After the user has chosen how many shares of which stocks they want to buy, you will print out their portfolio and then simulate the growth of their stocks over three years. To do this, you will use a for loop that utilizes a random number generator to change each of the stock prices from -10% to +20% every year (hint: that is 31 values). After each year, print out the new stock prices, the number of shares the user has, and the net worth of the user (don’t forget about their cash that was left over from buying stocks!).3. ImplementationIn this project, you will be given some “starter code” to help you get going. This will include the skeleton of your program and some helpful comments to push you in the right direction. Even with this starter code, it is important to incrementally write comments, add code, compile, and debug a little bit at a time as you go. This way, you always have a program that "does something" even if it is not complete.Using the random() function “random()” is a built-in C++ function that will return a random integer value. You should not have to include any library to access random(), but older versions of the C++ compiler required #include <random> int value;value = random(); // Value will be a “random” potentially large integerIf you want a random value between, say 1 and 10, you must take the result of rand and do a modulo operation to get the remainder when that value is divided by 10. value % 10 will give a value between 0..9, so add 1 to that get 1..10value = (random() %10) + 1; // value will be an integer between 1 and 10Note: you will get the same sequence of “random” numbers every time you run your program. If you want truly random numbers that change for each run, read about srandom() online or in Lab 6. Many programmers use rand() and srand() however those are older libraries and random() should be used instead.StyleYou should have a variety of variables that are named them appropriately and intentionally. Using comments will help organize your code (e.g. //Calculating total cost of ice cream).4. TestingYour program must run in OnlineGDB or by using g++ on Turing. Test your program with a variety of inputs to check that it operates correctly for all of the requirements listed above. Once your program is running correctly, you should run it several times with different choices to ensure that all options work as expected and to see the different outputs that are produced. Include the results of your experiments in your project report. Your program is required to have user input error checking capabilities (i.e. if the user enters an option that isn’t listed, such as ‘7’), but you do not need to handle unexpected data types (i.e. if the user enters a string instead of a numeric value).If you aren’t sure how to compile or execute your code, go the class website -> Lab Assignments -> Online GDB Tutorial for help.Sample OutputPlease see the next page of this document for a typescript of a possible output. Please use your own wording and be creative!5. DocumentationWhen you have completed your C++ program, write a short report using the “Programming Project Report Template” describing what the objectives were, what you did, and the status of the program. Does your program work properly for all test cases? Are there any known problems? Save this project report in a separate document to be submitted electronically.6. Project SubmissionIn this class, we will be using electronic project submission to make sure that all students hand their programming projects and labs on time, and to perform automatic plagiarism analysis of all programs that are submitted. When you have completed the tasks above go to Blackboard to upload your documentation (a single .docx or .pdf file), and your C++ program (a single .cpp file). Do NOT upload an executable version of your program.The dates on your electronic submission will be used to verify that you met the due date above. All late projects will receive reduced credit:10% off if less than 1 day late,20% off if less than 2 days late,30% off if less than 3 days late,no credit if more than 3 days late. You will receive partial credit for all programs that compile even if they do not meet all program requirements, so handing projects in on time is highly recommended. 7. Academic Honesty StatementStudents are expected to submit their own work on all programming projects, unless group projects have been explicitly assigned. Students are NOT allowed to distribute code to each other, or copy code from another individual or website. Students ARE allowed to use any materials on the class website, or in the textbook, or ask the instructor and/or GTAs for assistance.This course will be using highly effective program comparison software to calculate the similarity of all programs to each other, and to homework assignments from previous semesters. Please do not be tempted to plagiarize from another student.Violations of the policies above will be reported to the Provost's office and may result in a ZERO on the programming project, an F in the class, or suspension from the university, depending on the severity of the violation and any history of prior violations.Typescript (Sample Output)Script started on 2021-02-10 23:42:13-0600lstrothe@turing:~/FoundationsI$ g++ -Wall homework3.cpp -o homework3.exelstrothe@turing:~/FoundationsI$ ./homework3.exe Welcome to the stock market!You currently have $1000. Here are the stocks that are available: 1. AMC$80 2. GameStop$30 3. Pokemon$151 4. Nintendo$300 5. Quit>> 1You now have 1 shares of AMC.You currently have $920. Here are the stocks that are available: 1. AMC$80 2. GameStop$30 3. Pokemon$151 4. Nintendo$300 5. Quit>> 2You now have 1 shares of Gamestop.You currently have $890. Here are the stocks that are available: 1. AMC$80 2. GameStop$30 3. Pokemon$151 4. Nintendo$300 5. Quit>> 3You now have 1 shares of Pokemon.You currently have $739. Here are the stocks that are available: 1. AMC$80 2. GameStop$30 3. Pokemon$151 4. Nintendo$300 5. Quit>> 4You now have 1 shares of Nintendo.You currently have $439. Here are the stocks that are available: 1. AMC$80 2. GameStop$30 3. Pokemon$151 4. Nintendo$300 5. Quit>> 4You now have 2 shares of Nintendo.You currently have $139. Here are the stocks that are available: 1. AMC$80 2. GameStop$30 3. Pokemon$151 4. Nintendo$300 5. Quit>> 4You cannot afford Nintendo stock.You currently have $139. Here are the stocks that are available: 1. AMC$80 2. GameStop$30 3. Pokemon$151 4. Nintendo$300 5. Quit>> 0That was an invalid choice. Please try again.You currently have $139. Here are the stocks that are available: 1. AMC$80 2. GameStop$30 3. Pokemon$151 4. Nintendo$300 5. Quit>> 9That was an invalid choice. Please try again.You currently have $139. Here are the stocks that are available: 1. AMC$80 2. GameStop$30 3. Pokemon$151 4. Nintendo$300 5. Quit>> 1You now have 2 shares of AMC.You currently have $59. Here are the stocks that are available: 1. AMC$80 2. GameStop$30 3. Pokemon$151 4. Nintendo$300 5. Quit>> 2You now have 2 shares of Gamestop.You currently have $29. Here are the stocks that are available: 1. AMC$80 2. GameStop$30 3. Pokemon$151 4. Nintendo$300 5. Quit>> 5You have left the trading business with $29This is your portfolio: 2 AMC shares, each worth $80 for a total of $160 2 GameStop shares, each worth $30 for a total of $60 1 Pokemon shares, each worth $151 for a total of $151 2 Nintendo shares, each worth $300 for a total of $600 You also have $29 cash remaining.Your net worth is $1000.============ Year 1 Report ============AMC changed by 0% and is now worth $80.GameStop changed by -5% and is now worth $28.Pokemon changed by -7% and is now worth $140.Nintendo changed by -3% and is now worth $291.This is your portfolio: 2 AMC shares, each worth $80 for a total of $160 2 GameStop shares, each worth $28 for a total of $56 1 Pokemon shares, each worth $140 for a total of $140 2 Nintendo shares, each worth $291 for a total of $582 You also have $29 cash remaining.Your net worth is $967.============ Year 2 Report ============AMC changed by 9% and is now worth $87.GameStop changed by 8% and is now worth $30.Pokemon changed by -3% and is now worth $135.Nintendo changed by 2% and is now worth $296.This is your portfolio: 2 AMC shares, each worth $87 for a total of $174 2 GameStop shares, each worth $30 for a total of $60 1 Pokemon shares, each worth $135 for a total of $135 2 Nintendo shares, each worth $296 for a total of $592 You also have $29 cash remaining.Your net worth is $990.============ Year 3 Report ============AMC changed by 7% and is now worth $93.GameStop changed by 12% and is now worth $33.Pokemon changed by 19% and is now worth $160.Nintendo changed by 3% and is now worth $304.This is your portfolio: 2 AMC shares, each worth $93 for a total of $186 2 GameStop shares, each worth $33 for a total of $66 1 Pokemon shares, each worth $160 for a total of $160 2 Nintendo shares, each worth $304 for a total of $608 You also have $29 cash remaining.Your net worth is $1049.lstrothe@turing:~/FoundationsI$ exitexitScript done on 2021-02-10 23:43:11-0600 ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download