Question
Here is a declarion of a class called Student that has two int field classes(number of classes taken) and semester and a double field called
Here is a declarion of a class called Student that has two int field classes(number of classes taken) and semester and a double field called gap
Class Student
{
private:
int class, semester;
double gpa;
public:
void add_class(int n);
void add_semester (int n);
double class_gpa();
};
Add a declaration of a constructor in the class declaration above. It takes no parameter.
Write a member function definition for the constructor for the student class that set all the private data to zero.
Write a member function definition for class_ratio. Class_ratio returns the average number of classesd per semester for the student as a double value (double arithmetic should be used). If the student has attended zero semester, the value zero is returned.
Show a declarion of two variable Laura and Logan of type student in an application program.
Show a call to the member function definition class_ratio from the application program that finds the average number of classes that logan has taken each semester and places the result in the variable logan_average.
2. Say that we have a stack, s, as defined in class, with a stack _size of 6 (refer to the code for the stack class).
a. What type is the private data variable top in the stack class?
b. Show the private data values for an empty stack:
data
|
|
|
|
|
|
[0] [1] [2] [3] [4] [5]
|
top:
c. Show the status of the private data after each of the following sets of statements execute (continue from the stack above):
b. s.push(k)
data
|
|
|
|
|
|
[0] [1] [2] [3] [4] [5]
|
top:
c. s.pop();
data
|
|
|
|
|
|
[0] [1] [2] [3] [4] [5]
|
top:
d. After the pop, Is the character K still in the array?
e. After the pop, Is the character K still in the stack?
f. s.push(R);
data
|
|
|
|
|
|
[0] [1] [2] [3] [4] [5]
|
top:
new problem( not continue from above)
g. show the value of the private data variable after the constructor run:
data
|
|
|
|
|
|
[0] [1] [2] [3] [4] [5]
|
top:
Write a stack member function definition for the stack class in the implementation called second_bottom that print the elements second from the bottom on the stack. second_bottom takes no parameter and dose not return a value. For example:
Original Stack
K
R
P
T
S
second_bottom will print T. you may assume that there are at least two elements in the stack. The stack should not be changed.
Write a function definition for bottom in the application. That print the value of the bottom of the stack. It takes one call by value stack parameters, and dose not return a vlue. If the stack has no elements bottom should print a ?.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started