Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Write a function called changeLetter that can directly alter the value of a c

ID: 3777970 • Letter: 1

Question

1. Write a function called changeLetter that can directly alter the value of a character variable. It takes one argument: a reference to a character. It returns nothing. If the passed in character is alphabetic ('a' to 'z' or 'A' to 'Z'), then make the character become the next higher ASCII value ('a' becomes 'b' etc.). If the passed in character is not a letter, don't alter it.

2. Write a calling statement for the changeLetter function. It takes one argument: a reference to a character and returns nothing. The calling statement should pass the char variable ch so that it is (potentially) altered.

3. Write a calling statement for the changeLetter function. It takes one argument: a reference to a character and returns nothing. The calling statement should pass the 2nd character in a char array called chAr (by second, I mean the sub-oneth) so that it is (potentially) altered.

4. Assume the following function header:

void fn( int &n )

Write an instruction for the function body that will store 10 into the caller's variable referred to by n.

5. Write a calling statement for the fn function. It takes one argument: a reference to an integer and returns nothing. The calling should pass the integer variable num to the function so that it can be altered.

6. The strlen() function returns

the number of chars in an array of char, including the null

the number of chars in an array of char not including the null

the declared number of chars an array can hold

7. What must be true of the arguments to strcat(s1, s2); More than one answer may be correct

s1 must be valid strings

s2 must be a valid string

s1 must have room to contain the result

s2 must have room to contain the result

8. How is a structure different from an array?

9. Write a definition for a structure called Part that can hold a part name (an array of characters that can hold 24 characters plus a null terminator), a part weight (int), and a part price (float). Make up appropriate names.

10. Assume the following structure definition:

struct Person

{

char name[50];

int age;

};

Write a declaration for a variable of type Person and initialize it with your name and the age 10. This should be done as part of the variable declaration statement.

11. Assume the following structure definition:

struct Person

{

char name[50];

int age;

};

Write a declaration for a variable of type Person and initialize it with your name and the age 10. This should be done as several executable statements.

12. Declare an array of 10 Person structures named peopleArray.

13. Assume the following structure definition and declaration:

struct Person

{

char name[50];

int age;

};

Person people[265];

Assuming that the people array contains 265 valid structs, write code to print out the age member for each item in the structure.

Explanation / Answer

1) void changeLetter(char &ch){ /**function definition**/

    if((ch>='A'&&ch<='Z')||(ch>='a'&&ch<='z')){

                                ch++;

                }

                return;

}

2) changeLetter(ch);

3) changeLetter(chAt[1]);

4) void fn( int &n )

{

        n=10;

        return;

}

5) fn(num);

6) the number of chars in an array of char not including the null

7) s1 must be valid strings

s2 must be a valid string

s1 must have room to contain the result

8) a structure can store multiple types of data, but all array elements must be same type

9) struct Part{

        char name[25];

        int weight;

        float price;

};

10) struct Person

{

char name[50];

int age;

};

11) Person me={name, 10};//where name is char[50] cstring holding your name

12) Person me;

        strcpy(me.name,name);

        me.age=10;

13) for(int i=0;i<265;i++)

     {

        cout<<person[i].age<<endl;

          }