Question

____     1.   Assume you have the following declaration char nameList[100];. Which of the following ranges is...

____     1.   Assume you have the following declaration char nameList[100];. Which of the following ranges is valid for the index of the array nameList?

a.

0 through 99

c.

1 through 100

b.

0 through 100

d.

1 through 101

____     2.   Assume you have the following declaration int beta[50];. Which of the following is a valid element of beta?

a.

beta['0']

c.

beta[0]

b.

beta['1']

d.

beta[50]

____     3.   Suppose that sales is an array of 50 components of type double. Which of the following correctly initializes the array sales?

a.

for (int 1 = 1; j <= 49; j++)

    sales[j] = 0;

b.

for (int j = 1; j <= 50; j++)

    sales[j] = 0;

c.

for (int j = 0; j <= 49; j++)

    sales[j] = 0.0;

d.

for (int j = 0; j <= 50; j++)

    sales[j] = 0.0;

____      4   What is stored in alpha after the following code executes?

int alpha[5];

int j;

for (j = 0; j < 5; j++)

{

    alpha[j] = 2 * j;

   if (j % 2 == 1)

        alpha[j - 1] = alpha[j] + j;

}

a.

alpha = {0, 2, 4, 6, 8}

b.

alpha = {0, 2, 9, 6, 8}

c.

alpha = {0, 3, 4, 7, 8}

d.

alpha = {3, 2, 9, 6, 8}

b.

8

d.

10

      Programming Questions

Write a C++ program that lets the user enter rainfall for each of 12 months into an array of doubles. The program should calculate and display the total rainfall for the year and the average monthly rainfall.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1. a) 0 through 99

2. c) beta[0]

3. c) for (int j = 0; j <= 49; j++)
sales[j] = 0.0;

4. a) alpha = {0, 2, 4, 6, 8}

Program:

#include <iostream>

using namespace std;

int main()
{  
   double rainfall[12];
   double total=0.0, avg=0.0;

   for(int i=0;i<12;i++)
   {
       cout << "Enter " << i+1 <<" month rainfall : ";
       cin >> rainfall[i];
       total += rainfall[i];
   }

   cout << "Total rainfall of the year : " << total << endl;

   avg = total/12;

   cout << "Average monthly rainfall is : " << avg << endl;
   return 0;
}

Terminal OpenF guessing.py rainfall.cpp rainfall1.cpp #1nclude <tos trean ustng nanespace std 8 sasi@sasl-desktop: /Desktop/p

Add a comment
Know the answer?
Add Answer to:
____     1.   Assume you have the following declaration char nameList[100];. Which of the following ranges is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. (TCO 1) What is the output of the following C++ code? int list[5] = {0,...

    1. (TCO 1) What is the output of the following C++ code? int list[5] = {0, 5, 10, 15, 20}; int j; for (j = 0; j < 5; j++)      cout << list[j]; (Points : 4)         0 1 2 3 4         0 5 10 15         0 5 10 15 20         5 10 15 20 Question 2.2. (TCO 1) What is stored in alpha after the following code executes? int alpha[5] = {0}; int j; for (j = 0; j...

  • Assume you have the following declaration (in main) : int num[10] [7]; Assume that array num...

    Assume you have the following declaration (in main) : int num[10] [7]; Assume that array num is filled completely. Write functions to perform each of the following: a) A function that prints all elements in the array that are greater than 10 or less than 50. b) A function that finds the largest number in the array and returns its subscript. c) A function that finds and returns the average of all the numbers in the array. d) A function...

  • Assume that you declare a variable as int x = 100 ; and correctly pass it...

    Assume that you declare a variable as int x = 100 ; and correctly pass it to a method with the declaration private static void IncreaseValue (ref int x) .There is a single statement within the IncreaseValue () method: x = x + 25 ; . Back in the Main ( ) method, after the method call, what is the value of x ? a The program will not run 125 O c. It is impossible to tell. O d...

  • JAVA: Suppose you have the following array declaration and initialization:      int [ ] values;     ...

    JAVA: Suppose you have the following array declaration and initialization:      int [ ] values;      values = new int[18]; Suppose there is a static method called sumAll that is sent an integer array. The sumAll method computes and returns the sum of all the integers in the array that it is sent (assuming the array is filled). Choose the best example of calling this method: Group of answer choices a) sumAll( values[0], values.length ) b) sumAll( values[0 .. 17]...

  • 25. Given the array declaration double xyz [20]: which of the following statements are true? a....

    25. Given the array declaration double xyz [20]: which of the following statements are true? a. The array may hold up to 20 elements which may be accessed by the subscripts 0 through 20 b. The array may hold up to 21 elements which may be accessed by the subscripts 0 through 20 c. The array may hold up to 21 elements which may be accessed by the subscripts 0 through 19 d. The array may hold up to 20...

  • Program 2: Thread version int i = 100; char *buffer: void *tfuc(void *noarg) { int j...

    Program 2: Thread version int i = 100; char *buffer: void *tfuc(void *noarg) { int j = 0; printf("B:1-%d, j = %d\n",1,1); printf("B: I = %d, j = %d\n",1,1); j = 3; strcpy(buffer, "red"); Pthread exit(NULL); //print the string (show values of i, j) //print the string (show values of i,1) //copy the string "red" to buffer. int main(void) { pthread_t tid; //declaring vars int j = 1; buffer strcpy(malloc(100), "blue"); //Initialize buffer and copy the "blue" to it pthread_create(&tid,...

  • The array declaration in the following C program: main() { int a[10]; } can be replaced...

    The array declaration in the following C program: main() { int a[10]; } can be replaced by which of the following: A #include <stdlib.h> main() { int* a = (int *)malloc(10*sizeof(int)); } B #include <stdlib.h> main() { int[] a = new int[10]; } C #include <stdlib.h> main() { int* a = new int[10]; } D #include <stdlib.h> main() { int* a = (int *)malloc(20*sizeof(float)); }

  • in the missing code for the following program that initializes each variable with its row +...

    in the missing code for the following program that initializes each variable with its row + column. void init(int all [3], int i, int c) II initialize a 3x3 array: row & column int i, j; for (i=0; for(j=0; a[i] [5] = i+j; int main() { int a [3] [3); init return 1; _); // call init

  • C# 1.)Using the following declaration: int [ , ] exampleArray = {{3, 5, 6, 7}, {2,...

    C# 1.)Using the following declaration: int [ , ] exampleArray = {{3, 5, 6, 7}, {2, 8, 9, 22}, {1, 0, 4, 11}}; ______________ would be displayed if the following output statement was executed. WriteLine(exampleArray.Rank); 2.)Using the following declaration: int [ , ] exampleArray = {{3, 5, 6, 7}, {2, 8, 9, 22}, {1, 0, 4, 11}}; ______________ would be displayed if the following output statement was executed. WriteLine(exampleArray[0, 2]); 3.) Using the following declaration: int [ , ] exampleArray...

  • Consider the following C++ program // class declaration class person public: -person)i person ( ) person...

    Consider the following C++ program // class declaration class person public: -person)i person ( ) person (int age) i int get_age ()i private: int agei hi // class implementation person::-person age1ih person: :person age-1i) person: :person (int val) 1 ageval; > int person::get_age() return agei h int main) person lucky (42)i person group[1017 person fredi // code qoes here [8 points] Which of the following are valid C++ statements that could be compiled and executed in the main function above?...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT