Consider the following statements: struct nameType { string first; string last;
ID: 3634821 • Letter: C
Question
Consider the following statements:
struct nameType
{
string first;
string last;
};
struct dataType
{
int month;
int day;
int year;
};
struct personalInfoType
{
nameType name;
int pID;
dateType dob;
};
personalInfoType person;
personalInfoType classlist[100];
nameType student;
Mark the following statements as valid or invalid. If a statement is invalid, explain why.
a. person.name.first = "William";
b. cout << person.name << endl;
c. classList[1] = person;
d. classList[20].pID = 000011100;
e. person = classList[20];
f. student = person.name;
g. cin >> student;
h. for (int j = 0; j < 100; j++)
classlist[j].pID = 00000000;
i. classlist.dob.day = 1;
j. student = name;
Write C++ statements that do the following:
name : Mickey Doe
pID: 111111111
performanceRating: 2
dept: ACCT
salary: 34567.78
Explanation / Answer
Dear User, a) Valid. b) Invalid. Because only individual components at the lowest hierarchy can be output. c) Valid. d) Valid. e) Valid. f) Valid. g) Invalid. Because only individual member variables can be input. h) Valid. i) Invalid. classList is an array and thus need to provide index of the element. j) Invalid. Because ‘name’ cannot be used without the structure’s name to which it belongs. a) newEmployee.name.first =”Mickey”; newEmployee.name.second =”Doe”; newEmployee.pID = 111111111; newEmployee.performanceRating = 2; newEmployee.dept =”ACCT”; newEmployee.salary = 34567.78; b) for ( int i = 0; i < 100; i++) employees[ i ].performanceRating = 0; c) newEmployee = employees [19]; d) employees [49].salary += 5735.87;Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.