2010 Lab-9
Elements of this lab... . structured data . dynamic memory allocation . pointers . functionsHomework... Jump to homework section <--- clickProgram name: cars.cpp $ cd 2010 $ ./lab-start.sh $ cd 9 Here is a structure named Car. struct Car { string carMake; string carModel; int yearModel; double cost; }; Define an array of 35 of the Car structure variables. Initialize the first two eleiments with the following data: Make Model Year Cost ------ --------- ---- ------- Toyota Rav-4 2017 $33,500 Subaru Crosstrek 2019 $29,000 Write a loop that will step through the array you defined, displaying the contents of each element. sample outputlab-9 cars Toyota Rav-4 2017 $33,500 Subaru Crosstrek 2019 $29,000Estimated time to complete: 15 minutes.Program name: myarray.cpp in your program... Write a function that dynamically allocates an array of integers. The function will accept an integer argument indicating the number of elements to allocate. The function will return a pointer to the array. Call your function from main(). in main... Fill the array with single-digit numbers, then display them neatly going across the screen, not downward, no spaces. Delete the array before exiting the program. sample outputlab-9 my array Enter the number of array elements: 32 72618596058905827184750382746154Estimated time to complete: 25 minutes.Program name: reverse.cpp Reverse Array Write a function that accepts an int array and the array's size as arguments. You may use this array containing the first 10 digits of pi. int arr[10] = { 3,1,4,1,5,9,2,6,5,3 }; The function will create a copy of the array, except that the element values will be reversed in the copy. The function will return the address of the new array. No cout allowed in the function! Print only from main(). sample outputlab-9 reversed array original: 3141592653 reversed: 3562951413Estimated time to complete: 20 minutes.Program name: nobrackets.cpp Prompt the user to enter their name. Allocate an array of integers the same size as the user's name entered. Fill the array elements with the ASCII values of the name characters. Use these function prototypes in your program. Allocate and return an int array... int *makeArray(char *name); Fill the int array with ACSII values from name... void fillArray(char *name, int *arr, int n); Display the int array values... void displayArray(int *arr, int n); Do not use any [] operators in your 3 functions. The makeArray() function can use brackets for the new command only. If you have an array named arr... The first element of the array is at: *(arr + 0) The second element of the array is at: *(arr + 1) You take it from there. sample outputlab-9 no brackets program Please enter your name: Frederico Your letter values are: 70 114 101 100 101 114 105 99 111Be sure to delete the memory you allocated before the program ends. Estimated time to complete: 30 minutes.HOMEWORK HOMEWORK HOMEWORK HOMEWORK HOMEWORK HOMEWORK HOMEWORK HOMEWORK
Program name: 2010/9/pizza.cpp This program is required! Homework program by Brooklyn <--- click there
Program name: 2010/9/shuffle.cpp In your program, do the following... 1. In main(), dynamically allocate an integer array of size 52. 2. Fill the array with the values 1 through 52, in order. This array is a deck of playing cards. 3. Write a function named shuffle that will shuffle the deck of cards. 4. Pass the array and the number of cards in the deck to shuffle function. 5. Your function will have a loop that runs at least 10,000 iterations. 6. Each loop iteration - Generate 2 random numbers from 0 to 51. - These numbers are indices in the array. - Swap the two array elements using the two random indices. - Use the swap code we learned to do in class. - If the 2 random indices are equal, don't swap, but continue looping. - You may use the continue statement in your loop. 7. Return from your function back to main. 8. Deal the first 5 cards from the deck. 9. When displaying the card numbers, mod the number by 13, then display it. The numbers represent cards such as Ace, 2, 3, King, etc. 10. Inside your function, try not to use the [] operator. sample outputHomework-9 Deal one hand of poker Creating deck now. First 5 cards: 1 2 3 4 5 Shuffling deck now. Dealing 5 cards: 5 8 1 8 13Note: Some cards can have the same number because we are modding by 13. 52/13 = 4 Modding by 13 gives us 4 of each card number, like a real deck of cards. Estimated time to complete this program: 30 minutes.