Question

24. Consider the following C++ code. (6, 8) string seasons [4](*Winter, Spring, Summer, Falla) stringstrPtr; strPtr new string[5]; for (int į = 0; i < 4; i++) strPtr liseasons [i] a. Write a C++ code that outputs the contents of the array to whiclh strPtr points. Write the C++ statement that deallocates the memory space occu- pied by the array to which strptr points b.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

a.

To print the contents of array, use the cout<< standard output stream within for loop

1 #include <iostream> 3 using namespace sta; 4 5 int main() 8 9 10 string seasons [4]-fWinter, Spring , Summer, Fall;

b.

Using delete operator, we deallocates the memory allocated by using new operator dynamically

delete[] strPtr;   //freed the block of memory allocated to array

#include <!ostream» 2 using namespace sta; 4 int main() 6 string seasons [4]-fWinter, Spring , Summer, Fall; string *

Add a comment
Know the answer?
Add Answer to:
24. Consider the following C++ code. (6, 8) string seasons [4](*Winter", "Spring", "Summer", "Falla) stringstrPtr; strPtr...
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
  • Question #7. (8 points) (P313) The following algorithm yields the season (Spring, Summer, Fall or Winter)...

    Question #7. (8 points) (P313) The following algorithm yields the season (Spring, Summer, Fall or Winter) for a given month and day. If month is 1, 2, or 3, season "Winter Else if month is 4, 5, or 6, season "Spring" Else if month is 7, 8, or 9, season "Summer Else if month is 10, 11, or 12, season "Fall" If month is divisible by 3 and day 21 If season is winter, season = "Spring" Else if season...

  • Question 2 (a) Provide a single line of C++ code that will declare a variable that...

    Question 2 (a) Provide a single line of C++ code that will declare a variable that points to a string value, the variable is named x. [2 marks] (b) You have array c declared as string *c [5]; Give the single line of C+ + code that will assign the string pointer stored in variable x (from above) to the third element of the array c. [2 marks] (c) Write a for loop that initialises the contents of each element...

  • c++ Consider the following statement string str "Now is the time for the party!" What is...

    c++ Consider the following statement string str "Now is the time for the party!" What is the output of the following statements? (Assume that all parts are independent of each other.) a. cout <str·size ( ) end 1 ; b. Cout << str. substr (7, 8) <<endl: c. string: :size type indstr.find'£') string s str. substr (ind 4, 9); d. cout << str insert (11,"best " <<endl e. str.erase (16, 14) str.insert (16, "to study for the exam? ") cout...

  • 1. What is the output of the following code segment? int array[] = { 8, 6,...

    1. What is the output of the following code segment? int array[] = { 8, 6, 9, 7, 6, 4, 4, 5, 8, 10 }; System.out.println( "Index Value" ); for ( int i = 0; i < array.length; i++ ) System.out.printf( "%d %d\n", i, array[ i ] ); 2. What is the output of the following code segment? char sentence[] = {'H', 'o', 'w', ' ', 'a', 'r', 'e', ' ', 'y', 'o', 'u' }; String output = "The sentence...

  • Q21 Read the following code: 8 Points public class Main { public static int[][] doStuff() {...

    Q21 Read the following code: 8 Points public class Main { public static int[][] doStuff() { int[][] array2D = new int[3][2]; for (int i = 0; i < array2D.length; i++) { for (int j = 0; j < array2D[0].length; j++) { array2D[i][j] = (i+j)%2; } } return array2D; فه public static void main(String[] args) { int[][] a = doStuff(); مہ سره Q21.1 What are the contents of array a? 6 Points Write your answer as if printing the elements row-by-row....

  • 6. (4 points) The following code for insertion sort has been modified to print out the...

    6. (4 points) The following code for insertion sort has been modified to print out the sorted component of the array during the sort. What will be the output of running the main method of the following code? Try to trace by hand and then verify by executing the code public class Insertion ( public static void sort (String[] a) f int n- a.length; for (int i-1; i < n; i++) f for (int j i; j 0; j--) if...

  • basic c++ 2. AC++ program contains the following C++ code (assume an int occupies 2 bytes...

    basic c++ 2. AC++ program contains the following C++ code (assume an int occupies 2 bytes each in memory): int x[ ] = { 10, 20, 30, 40, 50, 60, 70, 80); int *ptrx ptrx = x; Array x starts at memory location 2140. a. What is the value assigned to ptrx? b. What is the value of (x+2)? c. What is the value of *x? d. What is the value of (*x+2)? e. What is the value of *(x+2)?...

  • In C Programming Language In this lab you will implement 4 string functions, two using array...

    In C Programming Language In this lab you will implement 4 string functions, two using array notation and two using pointers. The functions must have the signatures given below. You may not use any C library string functions. The functions are 1. int my strlen (char s ) - This function returns the number of characters in a string. You should use array notation for this function. 2. int my strcpy (char s [], char t I)- This function overwrites...

  • S1I Summer 09 Page 7 Practice Final Exam (30 points) Fill in the blanks to complete...

    S1I Summer 09 Page 7 Practice Final Exam (30 points) Fill in the blanks to complete the following recursive program It should print a pattern like the one below, using System.out.printin. The argument, lines, says how many lines long the pattern should be. Assume you have a method String nspaces(n) which returns a string containing n spaces. CYou should not write nspaces.) Here is the pattern when lines is 4. The first line VI. name has one space before the...

  • [IN JAVA] Copy the following code into your main.cpp and complete it public class Main { pub...

    [IN JAVA] Copy the following code into your main.cpp and complete it public class Main { public static void main(String [] args) { int [] array1 = {5, 8, 34, 7, 2, 46, 53, 12, 24, 65}; int numElements = 10; System.out.println("Part 1"); // Part 1 // Enter the statement to print the numbers in index 5 and index 8 // put a space in between the two numbers and a new line at the end // Enter the statement...

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