Question: C++ 1. Write a program that uses a dynamic array to compute the information about temperatures over a set of days. The first line of

C++ 1. Write a program that uses a dynamic array to compute the information about temperatures over a set of days. The first line of your file has a number that specifies how many temperatures follow. The next number of lines contain the temperatures. For example, your data file might look as follows:

8

66

62

70

71

71

70

59

59

Your program should do the following:

Declare an int pointer Temperature which will be used for the dynamic array

Declare an int variable numDays

Read in the number of days for which temperatures will be computed

Dynamically allocate an array large enough to hold that many days

Read the temperatures for each day into the array (use pointer notation)

Calculate the average temperature (use pointer notation)

Print out the result

2. Whats wrong with the following code? It should call a function to code a message into a secret string. Get it to run properly!

#include

#include

#include

using namespace std;

char codeIt(char * s)

{

int i;

int len = strlen(s);

char * result;

for (i = 0; i < len; i++)

result[i] = s[i] + 2;

result[i] = '\0';

return result;

}

int main()

{

char *str;

char *codedStr;

int strLen;

int len;

char ch;

int i;

cout << "Enter the size of the string: ";

cin >> strLen;

cout << endl;

cin.get(ch);

str = new char[strLen + 1];

cout << "Enter a string of length at most "

<< strLen << ": ";

cin.get(str, strLen + 1);

cout << endl;

codedStr = codeIt(str);

cout << codedStr;

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!