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

Briefly describe which elements of a class use the Pascal case, and what are the

ID: 3850655 • Letter: B

Question

Briefly describe which elements of a class use the Pascal case, and what are the best practices regarding the naming of these elements. What is static binding? What is dynamic binding? How do you distinguish between static binding and dynamic binding? Define and implement the overloaded constructors that support the following test function for a Triangle class. The data members for the Triangle class are: triangleBase- integer number height-integer number int main() {Triangle t1();//t1 will take all default value Triangle t2(3, 10);//t2 will take all supplied value Triangle t3(5);//t3 will take supplied triangleBase, height will take default value Triangle t4 = t2;//t4 will take the same value of t2//the rest of the code }

Explanation / Answer

1. The pascal casing is used for class name. FOr class names, Use upper case letters as word separators, lower case for the rest of a word

• First character in a name must be upper case
• No underscores (’ ’) are permitted

2. Static binding is function overloading, while the dynamic binding is when method is overriden in child class and that gets use. In short, Static binding is when binding is known at compile time.
So if we define a method in c++ source file as add(int x, int y), and in the same file from main method, if we call add(3,4), we are sure that call is going to hit the add function defined in this file itself. This is static binding.

Now for dynamic binding, consider below example. Here Base class defined a virtual method call task(), which need to be implemented by the child classes.

struct Base {
virtual int task() const { return 0; }
};
struct Child1: Base {
virtual int task() const override { return 1; }
};
struct Child2: Base {
virtual int task() const override { return 2; }
};

Base b = new Child1()
Here although b variable is a Base type object, but it refers to child1 class. so at run time, if we call b.task(), it will return as 1 rather than 0. This is in known as dynamic binding which is been decided by the object using that variable.


Answer 7:

#include <iostream>

using namespace std;

class Triangle
{
public:
   Triangle() {
       // default values
       trangleBase = 1;
       height = 1;
   }
   Triangle(int b) {
       trangleBase = b;
       height = 1;
   }
   Triangle(int b, int h) {
       trangleBase = b;
       height = h;
   }
  
private:
int trangleBase, height;
};

int main()
{
Triangle t1(), t2(3,10), t3(5);
Triangle t4 = t2;

return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote