Question

In: Computer Science

C++ programming test 2, chapters 6,7,& 9 on Functions, Arrays, & Pointers 1. Create a one...

C++ programming test 2, chapters 6,7,& 9 on Functions, Arrays, & Pointers

1. Create a one dimensional array, Ages, which will hold 4 ages. Each age is an int.

       b. Write a for loop and print, in reverse order the 4 values stored in memory assuming that the ages in the previous question have already been entered with a space between each value. Use subscript notation.

           

                        short cnt;

c. Do the same as above, but use pointer notation.

2. Create, but do not initialize with data, one array for each of the following situations. Use an appropriate data type and name for each array:

            a. holding the height of 10 students - 1 dimension - use most efficient storage size

     

            b. holding payments per year arranged like this table to be printed in a book

(Year and 1,2,3,4,5 are NOT part of the array. Neither are 6.5%, 6.75%, 7.0%)

                                    Year

                        1          2          3          4          5         

           

            6.5%     123.23    104.32    99.23     80.75     67.45   

                       

            6.75%    131.24    111.54   103.23    90.55     78.95

           

            7.0%      141.54    120.54   107.43    98.67     88.98

            There will be 75 tables like this for different amounts in the book.

            Create the array to hold these 75 tables.

3. Using the array name and proper subscripts, print the 120.54 from the above array considering it is the 62nd table in the array of tables.

           

4. Convert to pointer notation using the same variable:

                        data[9]

                        ddata[2][5]  

5. Use cout to print the address at which the following array is stored in the computer memory.

            short    YourData[12];

            a. Print the address of the first element of the array

            b. Print the address of the fifth element of the array

6. a. Given the following array and variables, print it so that all the items from 1 column are printed before any items on the second column, etc. Use for loop constructs, NOT while loop. Use subscript notation.

            float TestData[10][20];

            int row, col;

b. Dos the same as above using pointer notation.

7. Given the following, write the code to have C++ calculate:

            long Arr [100];

            a. Using the array name, Arr, calculate NUMBER OF BYTES IN ONE ELEMENT:

b. Calculate the NUMBER OF BYTES IN ONE ELEMENT using the data type

            (problematic for future code maintenance).

              c. Calculate the total number of bytes in the entire array.

              d. Calculate the number of elements in the array.

Anything relating to reference variables or arrays will be so described. Assume any others are by value

8. Write the header line for the following functions - each function is named F1

  1. A function returning a long and receiving as data parameters a short, an array of float and an array of double.

b. A function returning a reference to an int and receiving a 2 dimensional array of double with 23 columns.

c. Returning an int and receiving 3 int reference variables.

9. Write the following functions in full, including header line and body. Call each F1.

a. Receives 4 arguments, two arrays of short and two int's, one for each array, containing the count of array elements in that array. The function computes one grand total for both arrays. It then returns the grand total.

b. Receives an array of long. Returns the 2nd value stored in the array.

c. Write a function to receive a 2 dimensional array of long double with 10 columns. Also you will receive a short value representing the number of rows. The function totals all of the amounts in the array. The total of the values is returned as a long double.

d. . This function, F1, receives a pointer to an int array and a pointer to a double as arguments. It then calls the function called F2, which has the following prototype:

            void F2( int *arr, double num );

F1 is going to call F2 and send the array and the double value as arguments, receiving nothing back.

Write the entire function F1 which calls F2 as its only operation.

e. Change this function to reference variables:

float * fun1( float *a, int *b, float d)

{

                        *a = *b * d;

            return a;

}

Rewrite the entire function below:

Solutions

Expert Solution

Question 1:

a)


#include <stdio.h>

int main()
{
int ages[4]={13,23,45,60};
for(int i=3;i>=0;i--)
{
printf("%d ",ages[i]);
}
  
}

b)

#include <stdio.h>

int main()
{
int ages[4]={13,23,45,60};
int *start=ages;
int *end=ages+4;
for (int *i=end-1;i-ages>=0;i--)
{
printf("%d ",*i);
}
  
}


Related Solutions

C programming 4. Exploring Pointers and Use of Arrays [15 pts] In a shell environment, programs...
C programming 4. Exploring Pointers and Use of Arrays [15 pts] In a shell environment, programs are often executed using command lines arguments. For example: g++ -o cm03_la01 cm03_la01.c. In C such program can be develop using a standard for which the main program has two parameters as follows: int main (int argc, char * argv[ ]) { /*program here */ } 3 Because of the equivalence between pointers and arrays, the above C code can also be written as...
C++ PROGRAM (Pointers and char arrays) IMPORTANT NOTES: 1. CHAR ARRAY MUST BE USED. 2. YOU...
C++ PROGRAM (Pointers and char arrays) IMPORTANT NOTES: 1. CHAR ARRAY MUST BE USED. 2. YOU MUST USE POINTERS. 3. YOU MUST USE THE SWITCH STATEMENT TO EXECUTE THE PROGRAM. 4. ALL MODIFICATIONS MUST BE DONE IN THE SAME ORIGINAL CHAR ARRAY WITHOUT CREATING A NEW ONE. Write a C++ program that modifies a null teminated char array as follows: Consonants are positioned at the beginning of the string and vowels are moved to the end of the string. Example...
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2....
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2. Pass arrays to method and return an array from a method Problem 2: Find the largest value of each row of a 2D array             (filename: FindLargestValues.java) Write a method with the following header to return an array of integer values which are the largest values from each row of a 2D array of integer values public static int[] largestValues(int[][] num) For example, if...
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2....
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2. Pass arrays to method and return an array from a method Problem 1: Find the average of an array of numbers (filename: FindAverage.java) Write two overloaded methods with the following headers to find the average of an array of integer values and an array of double values: public static double average(int[] num) public static double average(double[] num) In the main method, first create an...
Write a C++ function that accepts array size and pointers to three arrays a1, a2 and...
Write a C++ function that accepts array size and pointers to three arrays a1, a2 and a3 of type float as parameters. It then multiplies a1 and a2 and stored the result in a3. Assume that array multiplication is done by multiplying corresponding array elements, e.g. a3[i] = a1[i] * a2[i] where 0 <= i <= (array size – 1) Write a C++ main program to dynamically create three equal sized float arrays a1, a2 and a3. The size of...
c++ Define polymorphism. What is the benefit of using pointers with polymorphic functions?
c++ Define polymorphism. What is the benefit of using pointers with polymorphic functions?
9) Create a java programming where you will enter two numbers and create only one method,...
9) Create a java programming where you will enter two numbers and create only one method, which will return or display addition, substraction, multiplication, division, average and check which number is greater than the other. Everything in one method and call it in main method.
Create a C++ file with given instructions below- Analyze random numbers Create two arrays, one int...
Create a C++ file with given instructions below- Analyze random numbers Create two arrays, one int one double. They should have 10 elements each Ask the user how many random numbers to generate. Then generate that many random numbers between 1 and 10. Use a for loop. Keep track of how many of each number in the range was generated (1 to 10) in the int array. Be sure to initialize the array to all 0's to start. Then, send...
Exercises on Arrays –using C++programming 1. You want an array with the numbers 100 – 105....
Exercises on Arrays –using C++programming 1. You want an array with the numbers 100 – 105. In the boxes below, fill in what your array should have. Fill in the index of each element below it. Array Index Open up your editor and write the following program: Declare an array that has the numbers 100 to 105. (How many elements are there in the array?) Print the array. Save your file and test it. Compare your results with your table...
Create the following functions for an array in C++. Test with size 10, 10,000 and 100,000....
Create the following functions for an array in C++. Test with size 10, 10,000 and 100,000. Time each sort. Merge sort Insertion Sort Selection Sort         Bubble Sort Quick Sort PLEASE DO IT IN C++
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT