原文地址:Array的練習
Introduction
完成Array相關練習。
Requirement
DO NOT use vectors to process data in your function algorithms.
This project can be a bit challenging as it involves working on and submitting three individual array processing-related programs (one for each scenario). For each program (a) carefully read the specification and the expected outcome (b) identify function types used, key types of parameters needed (value and reference) and the interface in main to test the function algorithms (c) write the algorithms with proper function setup (with function prototype and definitions - no inline function definitions) used to implement and meet the program specifications (d) test, debug algorithms written to ensure accurate output similar to the sample result provided and (e) finally set aside time to revisit the three completed programs to ensure proper program format, style, naming conventions and make sure to add function related documentation prior to submitting your project (no need to loose points for poor or none existent program documentation).
How to Submit
Using any standard C++ compiler write your program (aka. source) code, compile and debug your program until you show the correct program output. Submit your "source code" to the programming question below by saving it as a .cpp file and attaching it to the file submission area below.
Name your files as follows: LastName_p4a.cpp, LastName_p4b.cpp, LastName_p4c.cpp
Project 4a: Simple array manipulations
Scenario
Take a look at the code below - it declares two equally sized array.
The former is initialized with seven elements { 4, 7, 2, 8, 1, 3, 0 } the latter contains { 0, 0, 0, 0, 0, 0, 0 } values.
We want the second array to store the same values as the first one, but in a different order:
(1) Imagine that all the values have been moved one cell to the right, while the last element has gone to the first position. We can say that the array elements have been rotated to the right. (desired output: 0 4 7 2 8 1 3)
(2) Imagine that all the values have been placed in reverse order, while the last element has gone to the first position. We can say that the array elements have been reversed. (desired output: 0 3 1 8 2 7 4)
Warning: You must use two separate for loops to process the array elements in items 1 and 2 listed above. Don't use single assignments - they may work but they'll reflect badly on you and on your programming skills.
Once you get the expected results, play around a bit with your code: change just the array size to 10 and the initialization list of your array (for example... { 4, 7, 2, 8, 1, 3, 0, 1, 2 , 3 } ) and check if your program still executes properly.
Is your current algorithm still showing the desired output? If not, perhaps you may need to rethink a bit about the role of array subscripts (or index positions) and what is needed to correct your algorithm. Correct algorithm implementation with different array size/element based lists will be tested for grading purposes.
Project 4b: Simple array element checks
For the this second set of array processing related algorithms for this project ..write a program with two separate functions to process an array with limit valid elements. Demonstrate the two function algorithms in a driver program.
- a value-returning function to return the number of times a specified number occurs in an array.
- a void function that displays all of the numbers in the array along with respective subscripts (positions) that are greater than the number n.
Embed the two function definitions in a program and write a couple of drivers to test your functions carefully to make sure the results are correct. You may use the sample program interface provided above or create your own. Submit your final source code.
Project 4c: Collecting banknotes
Scenario
Once upon a time there was a country called Plusplusland. The monetary system they used there was simple: the currency name was the "plussar" and their central bank issued five different banknotes of values 50, 20, 10, 5 and 1 plussar.
Your task is to write a program for the ATMs of Plusplusland. In addition to main, the program should include at least one function and should find the minimal number of banknotes needed to deliver any amount of money to the client.
The Treasury Minister has asked you personally to do this. He expects your code to print the values of all the needed banknotes in a row - this is the format accepted by all ATMs in
Plusplusland. Your program will require the use of an integer array combined with a loop to check an element value and implement conditions to process the currency.
Test your code using the sample data provided below......
Example input
125
Example output
50 50 20 5
Example input
127
Example output
50 50 20 5 1 1
Example input
49
Example output
20 20 5 1 1 1 1
(HINT: Here is an array that maybe helpful for all known banknotes ordered from the most valuable to the least int banknotes[] = {50, 20, 10, 5, 1} and then use your skill with array related processing using a loop to process the currency correctly )
(本文出自csprojectedu.com,轉載請註明出處)