Question

In: Computer Science

Quiz 5 1.   Use the following definitions to “fill” the arrays. Write in both the data...

Quiz 5

1.   Use the following definitions to “fill” the arrays. Write in both the data (in the grid) and the index (below the grid). Cross out any unused locations. [6 each]

            a.          final int SIZE = 7;

            int nums [SIZE] = {5, 1, 3, 8, 4};

nums

                       

[     ]

[     ]

[     ]

[     ]

[     ]

[     ]

[     ]

[     ]

[     ]

[     ]

            b.         final int SIZE = 5;

            float values[SIZE] = {5.7, 3.2, 9.4, 2.5, 8.5};

values

                       

[     ]

[     ]

[     ]

[     ]

[     ]

[     ]

[     ]

[     ]

[     ]

[     ]

            c.          char letters[] = {'Z', 'Y', 'X', 'W', 'V', 'U'};

letters

                       

[     ]

[     ]

[     ]

[     ]

[     ]

[     ]

[     ]

[     ]

[     ]

[     ]

2.   Follow the segment of code, and use the grid to keep track of the array. Below, state only the requested values in the array at the conclusion of the code segment.

x

                       

[     ]

[     ]

[     ]

[     ]

[     ]

[     ]

[     ]

[     ]

[     ]

[     ]

final int SIZE = 6;

int x[SIZE] = {5, 7, 6, 2};

x[2] = x[1];

x[5] = 28;

x[1] = 15;

x[3] = x[1] * 2;

x[1] = 32;

x[2] = x[4];

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

            a.          x[1] = _____________ [1]

            b.         x[2] = _____________ [1]

            c.          x[3] = _____________ [1]

            d.         x[4] = _____________ [1]

            e.          x[5] = _____________ [1]

            f.          x[8] = _____________ [1]

Solutions

Expert Solution

1.

a.    

      final int SIZE = 7;

            int nums [SIZE] = {5, 1, 3, 8, 4};

nums

                   0

1

2

3

4

5

6

X

X

X

[   5 ]

[   1 ]

[ 3 ]

[ 8 ]

[ 4 ]

[ 0 ]

[ 0 ]

[   X ]

[ X ]

[ X ]

            b.         final int SIZE = 5;

            float values[SIZE] = {5.7, 3.2, 9.4, 2.5, 8.5};

values

                  0

1

2

3

4

X

X

X

X

X

[ 5.7 ]

[ 3.2    ]

[ 9.4 ]

[ 2.5 ]

[ 8.5 ]

[ X ]

[ X ]

[ X ]

[ X ]

[ X ]

            c.          char letters[] = {'Z', 'Y', 'X', 'W', 'V', 'U'};

letter

                 0

1

2

3

4

5

X

X

X

X

[   'Z' ]

[ 'Y' ]

[ 'X' ]

[ 'W' ]

[ 'V' ]

[ 'U' ]

[ X ]

[ X ]

[ X ]

[ X ]

=======================================================================

2.

final int SIZE = 6;

int x[SIZE] = {5, 7, 6, 2};

[ 5 ]

[ 7    ]

[ 6 ]

[ 2 ]

[ 0 ]

[ 0 ]

[ X ]

[ X ]

[ X ]

[ X ]

x[2] = x[1];

[ 5 ]

[ 7    ]

[ 7 ]

[ 2 ]

[ 0 ]

[ 0 ]

[ X ]

[ X ]

[ X ]

[ X ]

x[5] = 28;

[ 5 ]

[ 7    ]

[ 7 ]

[ 2 ]

[ 0 ]

[ 28 ]

[ X ]

[ X ]

[ X ]

[ X ]

x[1] = 15;

[ 5 ]

[ 15    ]

[ 7 ]

[ 2 ]

[ 0 ]

[ 28 ]

[ X ]

[ X ]

[ X ]

[ X ]

x[3] = x[1] * 2;

[ 5 ]

[ 15    ]

[ 7 ]

[ 30 ]

[ 0 ]

[ 28 ]

[ X ]

[ X ]

[ X ]

[ X ]

x[1] = 32;

[ 5 ]

[ 32    ]

[ 7 ]

[ 30 ]

[ 0 ]

[ 28 ]

[ X ]

[ X ]

[ X ]

[ X ]

x[2] = x[4];

[ 5 ]

[ 32    ]

[ 0 ]

[ 30 ]

[ 0 ]

[ 28 ]

[ X ]

[ X ]

[ X ]

[ X ]

a.          x[1] = ____32_________ [1]

            b.         x[2] = _____0________ [1]

            c.          x[3] = _____30________ [1]

            d.         x[4] = _____0________ [1]

            e.          x[5] = _____28________ [1]

            f.          x[8] = _____X________ [1]


Related Solutions

1.) Use the definitions given in the text to find both the odds for and the...
1.) Use the definitions given in the text to find both the odds for and the odds against the following event. -Flipping 4 fair coins and getting 0 heads. The odds for getting 0 heads are what to what.​(Type a whole​ number.) The odds against getting 0 heads are what to what. (Type a whole number) 2.) Determine whether the following individual events are overlapping or​ non-overlapping. Then find the probability of the combined event. Getting a sum of either...
The following program is used to sum arrays. Fill in blanks of the following program to...
The following program is used to sum arrays. Fill in blanks of the following program to complete the program and make the output is: s = 150. #include <iostream.h> class Arr { int *a,n; public: Arr():a(0),n(0){} Arr(int *aa, int nn) {n=nn; a=new int [n]; for(int i=0;i<nn;i++) *(a+i)=*(aa+i); } ~Arr(){delete a;} _____________ {return *(a+i);} }; void main() { int b [5]={10,20,30,40,50}; Arr a1(b,5); int i=0,s=0; _____________ s+=a1.GetValue(i); cout<<"s="<<s<<endl; }
Consider the following structure definitions and fill in the blanks for the enqueue function:
Consider the following structure definitions and fill in the blanks for the enqueue function:    typedef struct queue queue_t;     typedef struct node node_t;    struct node {         node_t *next;          void *val; };    struct queue {         node_t *head;         node_t *tail;};/* add val at the tail of the queue q */void enqueue (queue_t *q, void *val) {     if (q->head == NULL) {        _______________ = _______________ = malloc(sizeof(_______________));        _______________ = NULL;     } else {        _______________ = _______________ = malloc(sizeof(_______________));        _______________ = NULL;     }    q->tail->val = val; }
Definitions. Fill in the blank with the LETTER of the most appropriate term from the following:...
Definitions. Fill in the blank with the LETTER of the most appropriate term from the following: A. metal                                B. principal quantum number, n C. metalloid                           D. non-metal E. ionic bond                          F. azimuthal quantum number, l G. covalent bond                       H. magnetic quantum number, ml I. ionization energy                   J. atomic size K. polyatomic ion                       L. Lewis structure M. Bohr                                 N. Mendeleev O. polar bond                          P. octet rule R. electronegativity                   S. valence shell T. ion                                 V. periodic table _________ determines the shape of...
USE JAVA. Write a very general sort method that can sort any type of data arrays/lists....
USE JAVA. Write a very general sort method that can sort any type of data arrays/lists. For example, can sort a list of integers in ascending order, a list of integers in descending order, a list of doubles, a list of student objects (with names and scores) in ascending order of names, or in descending order of scores, … You can use any pre-defined sort function or can code your own. Use your favorite language for implementation. If your language...
In this quiz, use the following touchdown data for Tom Brady: Year Passing yards, y Touchdowns,...
In this quiz, use the following touchdown data for Tom Brady: Year Passing yards, y Touchdowns, t 2000 6 0 2001 2843 18 2002 3764 28 2003 3620 23 2004 3692 28 2005 4110 26 2006 3529 24 2007 4806 50 2008 76 0 2009 4398 28 2010 3900 36 2011 5235 39 2012 4827 34 2013 4343 25 2014 4109 33 2015 4770 36 2016 3554 28 2017 4577 32 2018 2748 17 2 (a) Find the correlation coefficient,...
In this quiz, use the following touchdown data for Tom Brady: Year Passing yards, y Touchdowns,...
In this quiz, use the following touchdown data for Tom Brady: Year Passing yards, y Touchdowns, t 2000 6 0 2001 2843 18 2002 3764 28 2003 3620 23 2004 3692 28 2005 4110 26 2006 3529 24 2007 4806 50 2008 76 0 2009 4398 28 2010 3900 36 2011 5235 39 2012 4827 34 2013 4343 25 2014 4109 33 2015 4770 36 2016 3554 28 2017 4577 32 2018 2748 17 2 (a) Find the correlation coefficient,...
Objectives:  Write classes in C++  Use dynamic arrays  Write and read from files...
Objectives:  Write classes in C++  Use dynamic arrays  Write and read from files 1. WriteaclassGradeBookcontainingthefollowing: Private attributes: - courseName: a string representing the name of the course. - nbOfStudents: an integer representing the number of students enrolled in the course. The number of students is greater than or equal to 5. - grades: a double dimensional array of integers representing the grades of Test1, Test2 and Final of every student. It should be a dynamic array. Public...
C++ DO not use arrays to write this program. Write a program that repeatedly generates three...
C++ DO not use arrays to write this program. Write a program that repeatedly generates three random integers in the range [1, 100] and continues as follows: If the right-most digit of all the three integers is equal, the program displays them in ascending order on the screen and continues. If the generated integers have different right-most digits, they are not displayed and the program continues. The program terminates once the right-most digits of all the three random numbers are...
You MUST use VECTORS in this lab. Do NOT use ARRAYS. Write code in C++ with...
You MUST use VECTORS in this lab. Do NOT use ARRAYS. Write code in C++ with //comments . Please include a screen shot of the output Part 4: Calorie Counting Specifications: Write a program that allows the user to enter the number of calories consumed per day. Store these calories in an integer vector. The user should be prompted to enter the calories over the course of one week (7 days). Your program should display the total calories consumed over...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT