Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C + + ONLY PLEASE Write the class declaration for a class named Animal that has the following member variables and member functions. Only the

C++ ONLY PLEASE
Write the class declaration for a class named Animal that has the following member variables and member functions. Only the
member functions should be public. The two member variables should be called name (string) and age (int). Member functions
should be named setValues, and display. (you could have more variables/functions in reality, but not needed here)
Default constructor: should set name to be *none* and age to be 0.(*none* and 0 are default values to both member var)
Overloaded constructor: should accept appropriate parameters for both name and age.
Destructor: should set all member variables to their default values, and display a message Animal left.
The setValues function should have no return and two input parameters for both name and age. The function should store the
parameters in both age and name. This is a mutator function
The display function is an accessor function, it should have no return type or parameters. It should output to the screen a line
similar to "Animal: [name], is [age] years old but using the values stored in the member variables (e.g. Animal: cat, is 5 years
old)
There should be two files involved, Animal.h and Animal.cpp
//Write your complete program Animal.h file here: (5pts)
2. Continuing with the previous problem, write your complete program Animal.cpp file here: (5 pts)
3. Continuing with the previous problem, given the following pointer, dynamically allocate an array of 3 objects. Use the pointer to
set all three objects values to be the values provided in the table, and then display all the values stored in the array. (5 pts)
Animal * ptr;
Name Age
cat 5
tiger 8
wildcat 10
4. Given the following binary file, (2 pts each)
1.33.25.17.49.80111213252.7192910.152.134681416
double var;
long s = sizeof(var);
Predict the output and explain your answer briefly:
file.seekg(4*s , ios::beg);
file.read(reinterpret_cast(&var);
sizeof(var))
cout << var;
file.seekg(-3*s, ios::cur);
file.read(reinterpret_cast(&var);
sizeof(var))
cout << var;
file.seekg(-6*s, ios::end);
file.read(reinterpret_cast(&var);
sizeof(var))
cout << var;
5. Declare a structure named Student, which has the following three member
a c-string of 80 chars name, an int for ID, a double for GPA(5 pts)
6. Continuing with the previous problem . Declare an object called freshman which is instantiated from Student. Ask user to enter
all corresponding information. A name may contain space. (5pts)
7. Continuing with the previous problem. First, open a binary file name record.dat. Use the structure and freshman object
declared above; write freshman objects data to the binary file. Close the file by the end. (5pts)
8. Continuing with the previous problem. Read the file that was created in problem 7(file is already opened), assuming you do not
know how many records there are, read from file and then display all records on console. (5pts)
9. Predict the output, and explain your answer briefly or with a diagram (2 pts each )
Program segment Your output and explanation
int i[]={12,9,3,5,7,2,1,0,-5,-6};
int *p1= &i[0];
int *p2= &i[2];
*p1=10;
*p2=11;
p1[3]=12;
p2[-1]=13;
cout <<*(p1+1);
char *s;
char p[15]= "Final Exam Day";
s = &p[3];
cout << s[2]<< endl;
int * p;
int array[]=
{3,4,5,1,2,0,-4,-1,0,-2,10,100};
p = array;
cout <<*p << endl;
p++;
cout <<*p << endl;
p +=5;
cout <<*p << endl;
p--;
cout <<*p << endl;
p = &array[10];
cout <<*p << endl;
10.(3pts) Given the following c-string, write a function that capitalizes all the letters.
char str [81]=hello world!
after calling your function, str becomes:
HELLO WORLD!
void capitalize_str (char *str)
{

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions