Write two or more of the programs starting at lab61.cpp
Do as many as you can.
Finishing one program perfectly should be your first goal.
Then, try more as you have time.
Each program is given a name indicated.
Do your work in your /2010/6 folder on Odin.
Steps in completing this assignment...
1. Write a program for each of the options below.
2. Each program will use one or more arrays.
3. Each program will call a function that works with the array.
4. Output should look just like the sample given.
Declare an array that will hold 10 integers.
Fill the array with random numbers from 1 to 80.
Display the array values forward.
Display the array values in reverse order.
Hint: use two different for-loops.
lab6a - 10 random numbers array forward: 43 35 58 66 55 80 4 13 69 46 array reverse: 46 69 13 4 80 55 66 58 35 43 done.
Declare a character array that will hold 100 characters.
Prompt the user to enter their name.
Do a cin into the array.
Display their name downwards. ↓
Hints:
1. Use a while loop.
2. Step through the array elements.
3. Display the character you find, followed by endl.
4. Stop when you find this character: '\0'
(backslash zero inside single-quotes.)
lab6b - your name please enter your name here: Gordon G o r d o n done.
Write a function that declares an integer array with size 10.
Fill the array with random numbers from 0 to 20.
Display the array elements in forward and reverse order, side-by-side.
lab61 - forward & reverse 3 18 11 10 2 16 12 4 15 10 10 15 4 12 16 2 10 11 18 3
Write a function that declares an integer array with size 10 or more.
Fill the array with random numbers from 0 to 30.
All array values must be unique.
No duplicate values are allowed in the array.
1. Keep track of how many good values are in the array. There will be zero to start. 2. Use a for-loop to read through the array and test for duplicates. If no duplicates found, add the new value to the array.Sample output:
lab62 - unique numbers only 9 8 3 0 23 15 26 18 6 30
Write a function that declares an integer array with size of at least 20.
Fill the array with random numbers from 0 to 100.
Indicate all duplicate values when displaying the array.
lab63 - show duplicates 17 65 <---duplicate 99 <---duplicate 37 0 36 44 5 25 99 <---duplicate 78 10 69 77 32 20 65 <---duplicate 13 12 31
Write a function that prompts the user to enter a sentence.
Store the sentence in one character array.
Step through the sentence characters using a loop.
Display the words individually.
lab64 - parse words Enter a sentence: Please buy Gordon a new laptop. word 1: Please word 2: buy word 3: Gordon word 4: a word 5: new word 6: laptop.
Hints: Display each character individually. When you find a space, go to a new line. Stop when you find a NULL character in the sentence. A space character is: ' ' a NULL character is: '\0' To input a whole sentence, you will need to use cin.getline(). Look it up in our textbook. sample: char sentence[200]; cin.getline(sentence, 200);
Write a function that declares an integer array with size 10.
Fill the array elements with 10 random integers between 0 and 100.
Add all the array elements together.
If the total is not 100, fill the array again.
Continue trying until the total is exactly 100.
lab65 - array sums to 100 9 9 12 21 3 24 22 46 5 51 9 60 0 60 0 60 13 73 27 100 number of tries: 670375
Write a function that declares an integer array with size 10.
Fill the array with random numbers from 0 to 20.
Display the array elements like in the sample.
Display the 2 smallest values in the array.
lab66 - two smallest 8 12 19 15 17 12 1 14 19 9 1 8 <--- 2 smallest values
Write a function that declares a float array with size 10.
Fill the array elements with random numbers between 0.0 and 999.9.
Display the array values in ascending sequence.
Display the sum of all array elements.
Show 1 decimal of precision throughout.
Note:
You are required to implement a sort algorithm that we will learn in class.
We have not learned it yet.
lab77 - sorted order 8.9 30.2 98.5 177.0 379.1 429.8 462.8 769.0 822.7 916.2 ------ 4094.2
The rand() function produces numbers in the range 0 to RAND_MAX. You can use RAND_MAX to scale any random number to fall within the range from 0.0 to 1.0 with a division. 0.0 / RAND_MAX = 0.0 RAND_MAX / RAND_MAX = 1.0 Use floating point numbers for this. Type-cast the rand() and RAND_MAX to float or double. rand() / RAND_MAX Typecast both using static_cast<float>