answersLogoWhite

0


Want this question answered?

Be notified when an answer is posted

Add your answer:

Earn +20 pts
Q: What does class d temporary operator mean?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Write a program to overload preincrement and postincrement operator?

#include<iostream.h> #include<conio.h> class num { private: int a,b,c,d; publ;ic: num(int j,int k,int m,int l) { a=j; b=k; c=m; d=l; } void show(void); void operator++(); }; void num::show() { cout<<................................................................... } void num::operator++() {++a;++b;++c;++d; } main() { clrscr(); num X(3,2,5,7); cout<<"b4 inc of x"; X.show(); ++X; cout<<"after inc of x"; X.show(); return 0; }


Program for derived class in cpp?

#include<iostream> class base { int m_data; public: base(const int data):m_data(data){} base(const base& cpy):m_data(cpy.m_data){} base& operator=(const int rhs){m_data=rhs;return(*this);} base& operator=(const base& rhs){m_data=rhs.m_data;return(*this);} virtual ~base(){} }; class derived { public: derived(const int data):base(data){} derived(const derived& cpy):base(cpy){} derived& operator=(const int rhs){return(base::operator=(rhs));} derived& operator=(const derived& rhs){return(base::operator=(rhs));} virtual ~derived(){} }; int main() { derived d=42; }


What is the valid class declaration header for the derived class d with base classes b1 and b2 A class d public b1 public b2 B class d class b1 class b2 C class d public b1 b2 D class d b1 b2?

What is the valid class declaration header for the derived class d with base classes b1 and b2?A. class d : public b1, public b2 {/*...*/};B. class d : class b1, class b2 {/*...*/};C. class d : public b1, b2 {/*...*/};D. class d : b1, b2 {/*...*/};The answer is A, C and D.B is not valid because "class" is not a valid access specifier.All the others are valid because private access is the default when the access specifier is omitted. Note that if class D were declared using the struct prefix, inheritance would default to public access rather than private.


Class D is derived from class B The class D does not contain any data members of its own Does the class D require constructors?

Yes, D requires constructors, because all classes require constructors. However, whether you need to actually define them or not depends on whether B has any constructors other than a default constructor and a copy constructor. To understand why all classes must have constructors you need to understand how the compiler-generated constructors work. All classes must have at least two constructors, one of which must be a copy constructor. If you do not define any constructors at all, the compiler automatically generates a default constructor (with no parameters) and a copy constructor. If you define any constructor, the compiler only generates the copy constructor unless you define your own. The compiler also generates an assignment operator and a destructor unless you provide your own. In many cases the compiler-generated constructors will be sufficient for your needs thus there is no need to define your own in these cases. However, if your class contains one or more pointers to memory that is exclusive to each instance of a class (not shared amongst them), then you must provide your own constructors, as well as an assignment operator and a destructor, in order to manage that memory correctly. This is because the compiler-generated versions will treat all pointers as being pointers to shared memory and will simply copy their addresses, not what they contain. You must override this behaviour and ensure that those pointers are deep-copied; copying the memory itself, not just the address. Constructors exist in order to initialise member variables. Even if your class has no member variables and therefore no real need for constructors, the compiler-generated constructors will still exist, as will the assignment operator and destructor, and it is important that you fully understand how these constructors work so that you will know exactly when you need to define your own and when you do not. Consider the following example: #include <iostream> class B { public: B():m_data(0){ std::cout << "B::B()" << std::endl; } B(const B& b):m_data(b.m_data){ std::cout << "B::B(const B&)" << std::endl; } B& operator= (const B& b){ m_data = b.m_data; std::cout << "B::operator= (const B&)" << std::endl; return( *this ); } virtual ~B(){ std::cout << "B::~B()" << std::endl; } void SetData(const int i){m_data=i; std::cout << "B::m_data=" << m_data << std::endl; } int GetData(){return m_data;} private: int m_data; }; class D: public B {}; // no members or constructors defined. int main() { D d1; // default constructor std::cout << "d1.GetData()==" << d1.GetData() << std::endl; d1.SetData( 100 ); std::cout << "d1.GetData()==" << d1.GetData() << std::endl; D d2(d1); // copy constructor -- same as: D d2 = *d; std::cout << "d2.GetData()==" << d2.GetData() << std::endl; d1.SetData( 200 ); std::cout << "d1.GetData()==" << d1.GetData() << std::endl; std::cout << "d2.GetData()==" << d2.GetData() << std::endl; d2 = d1; // assignment operator std::cout << "d2.GetData()==" << d2.GetData() << std::endl; std::cout << std::endl; return(0); } // All objects fall from scope here. Output: B::B() d1.GetData()==0 B::m_data=100 d1.GetData()==100 B::B(const B&) d2.GetData()==100 B::m_data=200 d1.GetData()==200 d2.GetData()==100 B::operator= (const B&) d2.GetData()==200 B::~B() B::~B() Since we provided no constructors in D it is difficult to see exactly what is going on here. In the main function we initially declare d1 to be of type D, but the first line of output is B::B(). Clearly the base class constructor is being invoked but it is not clear exactly how it was invoked. You'd be forgiven for thinking that since D inherits from B then it must inherit B's default constructor, but you cannot inherit constructors any more than you can inherit friends, operators or destructors from a base class. They are part of the interface but they are not part of the inheritable interface. The answer, of course, lies in the fact the compiler has generated constructors for us behind the scenes. But since we don't have access to them we cannot trace them. So let's just clarify exactly what's going on by explicitly declaring constructors exactly as the compiler would have generated them for us. Let's also include some trace code so that we can see how they relate to the existing traces: class D: public B { public: D():B(){ std::cout << "D::D()" << std::endl; } D(const D& d):B(d){ std::cout << "D::D(const D&)" << std::endl; } D& operator= (const D& d){ B::operator=( d ); std::cout << "D::operator= (const D&)" << std::endl; return( *this ); } ~D(){ std::cout << "D::~D()" << std::endl; } }; Output: B::B() D::D() d1.GetData()==0 B::m_data=100 d1.GetData()==100 B::B(const B&) D::D(const D&) d2.GetData()==100 B::m_data=200 d1.GetData()==200 d2.GetData()==100 B::operator= (const B&) D::operator= (const D&) d2.GetData()==200 D::~D() B::~B() D::~D() B::~B() Now things are somewhat clearer. Although B::B() looks like it was invoked before D::D(), they were actually invoked the other way around. Here's the default constructor for D: D():B(){ std::cout << "D::D()" << std::endl; } Note that before we enter the construction body (which contains the trace) we explicitly call the default constructor of B, hence it appears to be invoked first. However, this is, in fact, the correct order of events since we cannot construct an instance of D unless we first construct an instance of B. Only when B has been fully constructed can we then construct D. Note also that even if we'd omitted the call to B() in the initialisation list, it would have been invoked automatically for us. That is, if we do not specify a base class constructor, the default constructor is invoked automatically. This fact is vital when it comes to declaring copy constructors: D(const D& d):B(d){ std::cout << "D::D(const D&)" << std::endl; } Here, we've called the base class copy constructor from the initialisation list: B(d). We have to do this because if we omit it, we'll end up calling the default constructor instead, which is not what we expect of a copy constructor. Here's the output trace snippet we'd have encountered had we omitted it: d1.GetData()==100 B::B() D::D(const D&) d2.GetData()==0 Clearly, d2 cannot be a copy of d1 if their base class members differ, hence we must explicitly call the base class copy constructor (just as the compiler-generated copy constructor did). Note that the assignment operator is not a constructor (it applies to existing objects only) and therefore does not have an initialisation list. However, the function body invokes the base class method, just as the compiler-generated version did. The remainder of the output is fairly self-explanatory but note that destruction occurs in the reverse order of construction, thus D must be destroyed before B can be destroyed. Note also that since D is derived from B, B's constructor must be declared virtual. This is required because if we held a pointer to a derived class' base class and subsequently destroyed it, we would rightly expect the derived class' constructor to be invoked first. But if B's constructor were not virtual, we would end up destroying B alone, leaving an invalid instance of D in memory with no way to destroy it (a memory leak).


How do you determine class width?

Not sure what you mean by class width, but if you mean how do you determine the size of a class, the simplest way is to use the sizeof() operator. The value returned may be equal to or greater than the sum of all its member variables, depending on any adjustments made for memory alignment. If the class contains pointers to memory allocated on the heap, this memory will not be included in the total -- only the size of the pointers to those allocations will be considered. EDIT: Previous answer does not address the question. #include<stdio.h> main() { int n,m,i,max; printf("How many numbers(n) you going to enter:"); scanf("%d",&n); printf("Enter the numbers:"); scanf("%d",&m); max=m; for(i=2;i<=n;i++) { scanf("%d",&m); if(m>max) max=m; } printf("The Largest Number is %d",max); } Output: How many numbers(n) you going to enter:5 Enter the numbers: 25 410 362 5 56 The Largest Number is 410

Related questions

What does class D amplification mean?

Class-D amplification is where the amplifiers act as electronic switches.


What does d mean for class d fires?

Class D fires are fires in combustible metals such as sodium,magnesium, aluminum and potassium.


Does holding a learners permit mean you have a c class license?

No. It means you have a learner's permit. Licence classification varies by state. In some states, a Class C licence is a 'typical' licence, and, in other states, classes A, B, and C are reserved exclusively for CDLs, and a standard operator's permit would be class D or E.


If you receive a d in a class does that mean you fail?

No an f means you fail. a d you pass


Write a program to overload preincrement and postincrement operator?

#include<iostream.h> #include<conio.h> class num { private: int a,b,c,d; publ;ic: num(int j,int k,int m,int l) { a=j; b=k; c=m; d=l; } void show(void); void operator++(); }; void num::show() { cout<<................................................................... } void num::operator++() {++a;++b;++c;++d; } main() { clrscr(); num X(3,2,5,7); cout<<"b4 inc of x"; X.show(); ++X; cout<<"after inc of x"; X.show(); return 0; }


What does d class seat mean on etihad flight?

pearl buisiness


Program for derived class in cpp?

#include<iostream> class base { int m_data; public: base(const int data):m_data(data){} base(const base& cpy):m_data(cpy.m_data){} base& operator=(const int rhs){m_data=rhs;return(*this);} base& operator=(const base& rhs){m_data=rhs.m_data;return(*this);} virtual ~base(){} }; class derived { public: derived(const int data):base(data){} derived(const derived& cpy):base(cpy){} derived& operator=(const int rhs){return(base::operator=(rhs));} derived& operator=(const derived& rhs){return(base::operator=(rhs));} virtual ~derived(){} }; int main() { derived d=42; }


What is the valid class declaration header for the derived class d with base classes b1 and b2 A class d public b1 public b2 B class d class b1 class b2 C class d public b1 b2 D class d b1 b2?

What is the valid class declaration header for the derived class d with base classes b1 and b2?A. class d : public b1, public b2 {/*...*/};B. class d : class b1, class b2 {/*...*/};C. class d : public b1, b2 {/*...*/};D. class d : b1, b2 {/*...*/};The answer is A, C and D.B is not valid because "class" is not a valid access specifier.All the others are valid because private access is the default when the access specifier is omitted. Note that if class D were declared using the struct prefix, inheritance would default to public access rather than private.


What has the author D J Bradley written?

D. J. Bradley has written: 'THE OPERATOR'


What is the class of address for 46.39.42.05?

if you mean local vs. internet then i would say internet. (local is usually based around 198 numbers)


Is accumulated depreciation a permanent or temporary account?

A/D is not temporary. Depreciation expense is the YTD depreciation booked. A/D retains its balance year over year.


When was LNWR Class D created?

LNWR Class D was created in 1906.