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

c++ programming questions, most points to most complete! Question 31.31. Given t

ID: 3771782 • Letter: C

Question

c++ programming questions, most points to most complete!

Question 31.31. Given the following class and array declaration, how would you print out the age of the 10th person in the array?

class personClass
{
public:
void setAge(int newAge);
void setGender( char newGender);
void setSalary(float newSalary);

int getAge();
char getGender();
float getSalary();

private:
int age;
char gender;
float salary;
};

personClass people[100]; (Points : 2)
cout << people[10];
cout << people[9];
cout << people[9].age;
cout << people[9].getAge();

Question 32.32. When you have a class which has a dynamic array as one of it's members, you should also include _____________ in the class. (Points : 2)
a copy constructor
a default constructor
a destructor
the assignment operator
all of the above

Question 33.33. Given the following class definition and the following member function header, which is the correct way to output the private data?

class Person
{
public:
void outputPerson(ostream& out);

private:
int age;
float weight;
int id;
};

void Person::outputPerson(ostream& out)
{
//what goes here?
}
(Points : 2)
out << person.age << person.weight << person.id;
out << person;
out << age << weight << id;
outputPerson(person);

Question 34.34. A member function of a class should be made private (Points : 2)
always
only if it will never be used
if it will only be used by other members of the class
never, it is illegal to make a member function private.

Question 35.35. A class member function that automatically initializes the data members of a class is called (Points : 2)
the init function
an operator
a constructor
a cast

Question 36.36. Given the following class definition, what is missing?

class ItemClass
{
public:
ItemClass(int newSize, float newCost);
int getSize();
float getCost();
void setSize(int newSize);
void setCost(float newCost);

private:
int size;
float cost;
}; (Points : 2)
nothing
a default constructor
accessor functions
mutator functions

Explanation / Answer

4. cout << people[9].getAge();

cout is used to display value. people[9] is for 10 person.where getAge() is used for getting age.

3. cout << age << weight << id;

cout is output stream class.the insertion operator << may be used more than once here.

endl is used to add new line.

4. if it will only be used by other members of the class

private function will only be used by other members of the class.

5. constructor

.A class member function that automatically initializes the data members of a class is constructor.

6. default constructor

default constructor is ItemClass();

it always is named after the class and no arguments are taken. so, ItemClass(int newSize, float newCost); isn't default constructor.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote