2932 - EE2310_Lec13 Scoreboard

Time

2023/12/21 08:15:00 2023/12/21 10:00:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
14186 EE2310_Lec13-1
14188 EE2310_Lec13-2

14186 - EE2310_Lec13-1   

Description

Modify Lab 12-2 to include the following two pure virtual functions for the class GeometricObject

double getArea() const;
double getPerimeter() const;

This way, GeometricObject will become an abstract class, i.e. you can't declare any concrete object of this class. These two functions are designed to be overridden by later descendant classes later.

 

/* ----------------------------------------

 *  Do not change anything below

 */

void displayByReference(const GeometricObject &g) {
  cout << g.toString() << ": area = " << g.getArea()
       << ", perimeter = " << g.getPerimeter() << endl;
}

void displayByPointer(GeometricObject *ptr_g) {
  cout << ptr_g->toString() << ": area = " << ptr_g->getArea()
       << ", perimeter = " << ptr_g->getPerimeter() << endl;
}

int main() {
   Rectangle rectangle(2, 3, "orange", true);
   Square square(4, "blue", false);
   displayByReference(square);
   displayByPointer(&square);

}

Input

Output

Square object: area = 16, perimeter = 16
Square object: area = 16, perimeter = 16

Sample Input  Download

Sample Output  Download

Tags




Discuss




14188 - EE2310_Lec13-2   

Description

Re-write Lec 11 using templates.

Re-define the Stack_t as a generic class template as follows.

template <class T>
class Stack_t {
/* your member functions should take any class T

 * modify your data member well so it takes any class T, too

 */

};

 

Use the following main. Do not change it.


int main(){
    int input_size, max_size, pop_size;
    double temp;

    /* input stack's max size */
    cin >> max_size;


    /* constructor is to be called */
    Stack_t<double> my_stack(max_size);
    

    /* input elements to be pushed */
    cin >> input_size;
    for(int i=0; i<input_size; ++i){
        cin >> temp;
        my_stack.dynamic_push(temp);
    }


    /* input number of elements to be popped */
    cin >> pop_size;
    for(int i=0; i < pop_size-1; ++i){
        cout << my_stack.dynamic_pop() << ' ';
    }
    if (0 != pop_size){
        cout << my_stack.dynamic_pop() << endl;
    }

    my_stack.show();

    return 0;
}

 

 

 

 

 

Input

4
9
21.2 6 3 65.1 7 91.333 4 5.23 8
0

Output

Stack contains 9 element(s)
21.2 6 3 65.1 7 91.333 4 5.23 8
top = 9, max_size = 16

Sample Input  Download

Sample Output  Download

Tags




Discuss