3460:209 Assignment 1 Assignment 1 myCode: the Programming Wizard Overview The purpose of this assignment is to make sure that you know how to write a program that does basic input, output, flow of...

1 answer below »

3460:209 Assignment 1



Assignment 1 myCode: the Programming Wizard



Overview


The purpose of this assignment is to make sure that you know how to write a program that does basic input, output, flow of control and/or calculations, and iterations. This part of the project’s task list is exclusive to what we are learning in class. Do not use advanced techniques, for example, do NOT use functions if we have not yet covered them. If this occurs it will invalidate your program and it will not receive consideration




HOW THESE ASSIGNMENTS WORK


You will notice that, in the code that has been provided for you, there are sections at the bottom of the program (where it says PLACE CODE HERE FOR EACH TASK) that are made to hold each coding effort for that particular task. They are enumerated and sequentially listed in the program. You will put your code inside of each function that has been created for each task. So, for example, when working on the code for task 1, variables, you will place your code inside (between the {braces}) where you find variables(). What happens is the program is run and we demonstrate each task by choosing it from the menu, which in turn executes your code for the task. Write your code as it appears in the order provided in the instructions. Unless otherwise specified, place your code in between the braces for each task. Ask questions about this process and we shall cover it in class as well.


IMPORTANT: If your code is misplaced the grade will be zero for the task. Also, you must use the prescribed variable names for each task to receive credit. Write your code as it appears in the order provided in the instructions. Ask any questions about this process.




PROGRAM SPECIFICATION


For the assignment, we will build out a variety of code to exercise the main parts of what we have learned in Unit 1. Suggest that you try writing your code in parallel with our discussions. Download the cpp file on the Brightspace repository called myCodePart1. Please see above as to how to use this program. Pause after each task (use cin.get()). Our program will be separated into different parts that follow from the menu…


1)Variables


A.Declare three variables named var1, var2, and var3, of the types char, int, float. Display them*.


B.Using the same three variables of the types char, int, float, assign their type appropriate values in each of them. Display them.


C.Change the value of var1 by assigning the value of 99 and print “I changed var1 and here is what happened: “ followed by the variable.


D.This next section goes at the top of your program. There are comments to help you locate where, around line 21 see the comment PLACE ALL OF TASK1'S stuff HERE, below. Include five different pre-processor directives (up at the top of the program where the other includes are) and provide comments in your code describing what it is used for. Such as: #include // this is used for output formatting, and so on. You want to use a resource or the book for this btw.


E.This section also goes at the top of your program. Provide the declaration (using) of three different names for standard namespace from your #includes. Describe them with comments. Note for parts D and E, we probably will not use them but rather just research them.


* For part 1 and part 2, we are going to use the printf() function. Printf is an old C language function, and it uses a format specifier to display the values of various types. The format specifier is fairly straight-forward, and works like this: we use %d to display the value of an integer variable, %c is used to display character, %f for float variable, %s for string variable, %lf for double and %x for hexadecimal variable. To generate a newline, we use “\n” in the C printf() statement. Here is an example that is assuming myVar is an int:


printf("Integer value is %d \n", myVar);



2)Console Input


A.Copy and reuse the previously declared three variables created from part one B, and perform three input statements for each of those variables. Display them after the input is complete.


B.Declare and initialize three variables var4 of the type char, var5 a string, and var6 a float. Input into the three variables in your program in the same order and use a get(), a getline(), and the extraction operator >>, respectively. Yes, it has to be in that order. Output them as well, one by one.


C.Using string var5, see if you can input the word “yo toe is big” using the input (extraction) operator, >>. Display var5. Now correct the issue and display “corrected var5: “ followed by the string’s value.


D.Declare two short integer type variables (var7 and var8) and take their values using only one >>, that is, do this input in the same statement. Display the result.


E.Using var7, store (assign) 32800 to the variable and display it, then display a message stating what happened (why it is not 32800).


F.Using var7, try to input the value ‘a’ into this variable and print. Print out a comment to describe what happened.



3)Console Output


A.Copy and reuse the previously declared three types of variables created from part two A, and now perform three cout statements for each of those variables. Note we no longer will use printf(). Goodbye old friend!


B.Declare three variables var4, var5, and var6, of the type float, and initialize them with values of your choosing. Output the result of adding the three variables together by storing the result into a variable, var7, and then follow with a display of var7. Next, in a single statement, output the sum of the three variables by doing the calculation without the use of a variable in the cout statement itself.


C.Using the previous three variables, write another section of cout to output them so that the display will show any decimal to the right (even when zeroes), will show up to a precision of seven, and will show fixed point notation.


D.Using var4-6, the floats, output them in columns that are fifteen wide, and justify (start displaying) on the right. Keep the same output settings that we had going from part C above, fixed point and all…


E.Add headings to the previous part. Named them “var 4”, “var 5” and “var 6”. This is a cout statement that you display prior to the output in step D. Headings are identifiers in programming, identifying the values in a particular column.


F.Finally display the floats with leading zeroes. Go look up how to use setfill() for this one. When combined with setw, it works well. Make sure you reset the fill character!



4)Operations


A.Create a variable that is a float called var4 and another float called var5, and assign them values 45.77 and 77.43. Calculate an overall percentage into var6 (representing the sum of the total points (var4) earned divided by the total points possible (var5)) and output it as a percentage. Now display “the percentage is: “ and var6 in an output statement.


B.Create three integer type variables, var1, var2, and var3. Initialize var2 to 4 and var3 to 7. Avoiding truncation, divide var2 by var3, saving the final result in var24. Display “the result without truncation is: “ followed by the result.


C.Create a long long double var7. Set var7 to the result of 200000 * 8000, and display the result.


D.We are going to write some code that determines if a number is within a range and if it is a valid number. Create var8, an integer, and take an input value from the user (cin) using var8 to hold the value. Now code something that can test the value for being in range (between 0 and 999) and for being a valid number, and then display the outcome (using cout, of course). Make sure you validated the value (see Lab 3 for code to do that).



5)Decisions


A.Use the variables from part 4A and the code that calculates an overall percentage (sum of the total points earned divided by the total points possible), and then output the percentage, determining a letter grade from that percentage (var6) by using the following scale:


a.A: 93%-100% ; A-: 90%-92.99% ; B+: 87%-89.99% ; B: 83%-86.99%; B-: 80%-82.99%; C+: 77%-79.99%; C: 73%-76.99%; C-: 70%-72.99%; D+: 67%-69.99%; D: 63%-66.99%; D-: 60%-62.99%; F: Less than 60%.


b.Print out “the letter grade is” followed by the correct letter grade value.


B.Create a bool variable called var4. Test to see whether the variable is on or off, that is, whether the var4 variable is true or false (you can assign it to either). If it is true then display “the strategy calls for the university to buy bean bags”, otherwise, display “the strategy saves expenditures for the university”.


C.Create a decision structure that has an expression that compares the result of a computation (1.5 * 77) to that of the value of the variable var5. Create and initialize var5 to 55.7234. Display “the computation is greater” or “var5 is greater”, depending upon whichever was greater than the other.


D.Create var6 as a short int and set it to 199, and var7 as a bool and set it to true. Next, write a test based on compound (multiple) conditions. We got information that var6 almost always determines the outcome (80% of the time). With that in mind, write the test as an if-else: if var7 is true and var6 is greater than 150, then the entire test is true, otherwise if either one of them is not then the entire test is false. Make sure you leverage short-circuiting. Display “the test is true” or “the test is false”.



6)Iterations


A.Copy and paste your code from part 5A that determined a grade from the sum of the total points earned divided by the total points possible. Make updates to the code using this new logic:


a.Ask the user for the input of the var4 (total possible) and var5 (total earned) in a loop that runs ten times. This will generate ten pairings of possible total points and total earned. You will then repetitively perform the same calculation (using var6) as before, and use the same coding from before to output the percentage, determine the letter grade, display the letter grade… try cut and paste.


b.Add validation: validate the inputs (must bebothnumeric and within the range) each time. Make sure you validate against non-numeric input.


·The scores and possible points are ranges 1 through 100.


B.Create a char variable var7 and set it to blank. Next, create a repeating menu with that asks for the “punctuation mark compare generator:”. Input the user response into the variable var7. Within the menu, create a char variable var8 to use within the loop. Set var8 to NULL. Each time the loop runs, display “your punctuation was lower than before” or “your punctuation was higher than before” as var7 is compared to var8. The first time it will be greater as it compares to NULL. Useispunct()in your code. We need to compare the last entry with the new one. Do you get what to do with var8? Repeat the menu as long as the user does not enter ‘z’.


C.Create an integer var9 and set it to 100. Create a loop structure where var9 counts down the iterations by halving the counter each time. The moment that it reaches 0 or less, it exits. Print the values of var9 with each pass.


D.Use theforloop with the same counter variable var9 for this next part. Do not alter var9 as it should be zero. Write some code that uses this for loop to display the character equivalent values for the ASCII codes 0through 127. Display 32 characters on each line.



7)Validations


A.Create a char variable var10 and set it to blank and ask the user to input a letter (char type). Next, see if you can validate that the user has entered a valid letter, Aa-Zz, using the ACSII equivalent to test with, and print the value of the asci equivalent of var10 followed by “was valid” or “was invalid”.



8)Miscellaneous



A.Fix the code that is given. Add (cout) a comment to explain what is going on, and why?



B.Try to improve the given code (rewrite it). Add (cout) a comment to explain what is going on, and why?



C.Define an integer called myNumber, and use two different cout statements to display the number ++ (postfix), and the ++ number (prefix) within a cout statement. Start myNumber out at your favorite value.







Make sure that your programs follow good documentation standards and follow the requirements for assignments. Reference the rubric standards on Brightspace.



Submission Instructions – for programming solutions


On Brightspace go to the matching Assignments for the ASSGN@, where @ is the number or character of the problem assigned and submit the program (cpp) file.



Last updated 7.09.2021 by Will Crissey.






Be aware that programming falls under all of the rules of plagiarism. Be careful when using any coding found in the outside world that is not your own. Any evidence of plagiarism is subject to sanctions like forfeits, suspension, and even ejection, as determined by theDepartment of Student Conduct and Community Standards.






COPYRIGHT © 2020 Will Crissey, Jr., Associate Professor, All rights reserved.




This document is intended exclusively for use by The University of Akron's Department of Computer Science. Do not distribute document copies to the public in any way.





THIS PROGRAM'S CONTENT IS PROTECTED


The document and associated content are either the property of, or used with permission by, The University of Akron, Department of Computer Science and may be protected by copyright and other restrictions. Copyrights in the site content may also be owned by individuals and entities other than, and in addition to, The University of Akron,Department of Computer Science. The use of this document by you, or anyone else authorized by you, is prohibited, except for purposes of completing the homework/project. Any unauthorized use of the document may violate copyright laws, trademark laws, the laws of privacy and publicity, and communications regulations and statutes.



Answered 122 days AfterSep 05, 2021

Answer To: 3460:209 Assignment 1 Assignment 1 myCode: the Programming Wizard Overview The purpose of this...

Darshan answered on Jan 06 2022
108 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here