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

Given the declaration of the Name type in Exercise 12, and the following declara

ID: 3922789 • Letter: G

Question

Given the declaration of the Name type in Exercise 12, and the following declarations: struct studentRecord {Name studentName; Name teacherName; int gradeNumber; string grades;} studentRecord sally; How would you assign the name Sally Ellen Strong to the studentName field of variable sally? How would you assign the grade number 7 to that field of sally? How would you assign the fourth letter from the grades field to char variable spring? Given the following declarations: struct Name {string first; string middle; string last;}; Name yourName; Name myName; What are the contents of the two Name variables after each of the following statements, assuming they are executed in the order listed? yourName.first = "George"; yourName.last = "Smith"; myName = yourName; myName.middle = "Nathaniel"; yourName.middle = myName.middle.at(0) + ".";

Explanation / Answer

Given structure of studentRecord is as follows
struct studentRecord
{
Name studentName;
Name teacherName;
int gradeNumber;
string grades;
}
studentRecord sally;

a) Setting the name Sally Ellen Strong to studentName in sttudentRecord

sally.Name="Sally Ellen Strong";

b)Setting the grade number 7 to the grade of sally

sally.gradeNumber=7;

c)Setting fourth letter of grades field
sally.grades[3]=spring[3];

Since index of the string starts from 0.

Given Name structure

struct Name
{
string first;
string middle;
string last;
};

Name yourName;
Name myName;

a.yourName.first="George"

yourName
first="George"
middle =null;
last=null;
myName=null;

b)
yourName.last="Smith"

yourName
first="George"
middle =null;
last="Smith";
myName=null;

c)
myName=yourName;

yourName
first="George"
middle =null;
last="Smith";

myName
myName.first="George"
myName.middle =null;
myName.last="Smith";

d)
myName.middle="Nathaniel";

myName
myName.first="George"
myName.middle ="Nathaniel";
myName.last="Smith";

e)
yourName.middle=myname.middle.at(0)+".";

yourName
middle="N."

The middle string index value is replaced with first letter of the middle string
and '.'

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote