You have an array having numbers 1 to 100 but one number is missing? Find out the missing number?
What are the disadvantages of c++?
Java is Beautiful Language , & who said that in java you don't required any logical aptitude.. now slowly c++ will be disappear
C++ has plenty of features than C, so a lot of syntax needs to be know by the programmer. Well when we need more, we should learn more.Another disadvantage is that C++ is not suitable for embedded co...
Code
class base { public: virtual void display(int i = 10) { cout<<"Base class display with i = "<<i<<endl; } }; class derived : public base { public: void display(int i = 20) { cout<<"Derived class display with i = "<< i <<endl; } }; int main(int argc, char *argv[]) { base *bptr = new derived; bptr->display(); return 0; }
Overriding function default argument takes more precedence ,Hence based class default argument 10 will be initialized to i.So i value holds 10 will be printed for this call with derived count statement.
Answer is : "derived class display with i=10"
What is the difference between an object and a class?
classes and objects are separate but related concepts. Every object belongs to a class and every class contains one or more related objects. Ø a class is static. All of the attributes of a class are fixed before, during, and after the execution of a program....
A class is a user defined data type which is used to declare objects and define the methods and functions to use the object.
An object is an instance of a class. it can be generated according to our needs whenever we want to use that. but classes once declared cant destroyed.
Both are hardly interrelated. Object 1. Basic runtime entities in object oriented environment. 2. Objects belong to only one class. ...
What is the difference between class and structure?
Structure: initially (in c) a structure was used to bundle different type of data types together to perform a particular functionality. But C++ extended the structure to contain functions also. The major difference is that all declarations inside a structure are by default public. Class: class is a...
Answered by: sumitv
Member Since Sep-2008 | Answered On : Sep 4th, 2008
Structure does support inheritance.
try out the following code.
#include<iostream>
using namespace std;
struct Base
{
int A;
};
struct Derived:public Base
{
int B;
void display();
};
void Derived::display()
{
cout<<endl<<"A = "<<A<<endl;
}
int main()
{
Derived D;
D.A = 111;
D.display();
getchar();
return 0;
}
Try out private and protected inheritance as well. It works. :)
Regards,
Sumit
inline can be used in structures ...it is possible to work
structure support multiple inheritence also try this code"cpp struct stud1 { int x; float y; stud1(int x,float y) { this->x = x; this->y = y; } }; struct stud2:public stu...
Abstraction is of the process of hiding unwanted details from the user.
Abstraction exactly involve the process of involving relevant things while ignoring the irrelevant things.
abstraction is the process of hiding the things which are not required and revealing the things which are required
Matrix operation using operator overloading
Write a program for four atrithmetic operations in matrix using operator overloading.
In both the above answers the op overloads should be using a const ref as input. You should have a (private) ctor that makes the matrix from the data, and should use RVO in the return.
Code
#include<iostream.h> #include<conio.h> class matrix { private:long m[5][5]; int row;int col; public:void getdata(); int operator ==(matrix); matrix operator+(matrix); matrix operator-(matrix); friend ostream & operator << (ostream &,matrix &); }; /* function to check whether the order of matrix are same or not */ int matrix::operator==(matrix cm) { if(row==cm.row && col==cm.col) { return 1; } return 0; } /* function to read data for matrix*/ void matrix::getdata() { cout<<"enter the number of rows "; cin>>row; cout<<"enter the number of columns "; cin>>col; cout<<"enter the elements of the matrix "; for(int i=0;i<row;i++) { for(int j=0;j<col;j++) { cin>>m[i][j]; } } } /* function to add two matrix */ matrix matrix::operator+(matrix am) { matrix temp; for(int i=0;i<row;i++) { for(int j=0;j<col;j++) { temp.m[i][j]=m[i][j]+am.m[i][j]; } temp.row=row; temp.col=col; } return temp; } /* function to subtract two matrix */ matrix matrix::operator-(matrix sm) { matrix temp; for(int i=0;i<row;i++) { for(int j=0;j<col;j++) { temp.m[i][j]=m[i][j]-sm.m[i][j]; } temp.row=row; temp.col=col; } return temp; } /* function to display the contents of the matrix */ ostream & operator <<(ostream &fout,matrix &d) { for(int i=0;i<d.col;i++) { for(int j=0;j<d.col;j++) { fout<<d.m[i][j]; cout<<" "; } cout<<endl; } return fout; } /* main function */ void main() { matrix m1,m2,m3,m4; clrscr(); m1.getdata(); m2.getdata(); if(m1==m2) { m3=m1+m2; m4=m1-m2; cout<<"Addition of matrices "; cout<<"the result is "; cout<<m3; cout<<"subtraction of matrices "; cout<<"The result is "; cout<<m4; } else { cout<<"order of the input matrices is not identical "; } getch(); }
Can time delay be generated in C through loops? If yes,how?
Yes, delay can be produced using the loops. but the delay cannt be same on all processors. That means, each processor shall have its own speed of executing an instruction. hence the execution speed in...
Local variables are stored in stack - each method have a stack frame (a fixed size of memory in the stack) that is allocated for local variables each time the method is called, and deallocated when th...
Hi,
I have a query. The lifetime of the static variable is the entire program - if it is a local auto variable (i.e., not dynamically allocated), will it contribute to the peak memory ?
Regards,
Ramanu
What is meant by class space and object space (with regards to memory) in c++?
I am a slow learner so I would like to have answers that are simple in words but brief.
Why the size of empty class is one byte?
Yes, but we can put in other way also as we all know we have some default memfunctions created by compiler they are default constructor, default destructor, default copyactor, default assignment opera...
As per MSDN: "The sizeof operator never yields 0, even for an empty class." When you calculate the size of a empty class that time you can c it takes 1 byte.which is the size of a char which...
Packaging an object’s variables within its methods is called encapsulation.
The wrapping up of data and code into a single entity is known as encapsulation.It is a way to implement data abstraction
encapsulation is the process of wrapping of data member and functions in to a single unit
Write a simple program for finding factorial in C++ ?
Code
class factorial { public static void main(String args[]) int f=1,i,n; n=Convert.ToInt32(Console.ReadLine()); for(i=1;i<=n;i++) { f=f*i; } Console.WriteLine("factorial of the no :"+f); Console.ReadKey(); }
Code
#include<iostream.h> #include<conio.h> void main() { clrscr(); int a,i,f=1; cout<<"Enter the Number whose factorial value is to be find "; cin>>a; for(i=a;i>0;i--) { f=f*i; } cout<<"Fctorial is "<<f; getch(); }
What do you understand by complexity?
What are different modes in which a file can be opened?
What are the different ways to declare a structure variable?
What is significance of calloc function in c?
Empty declaration of a class holds memory 1 byte
Why empty declaration of a class holds memory 1 byte. Explain briefly?
Different objects must have different addresses.
Code
Something *somethigns = new Something[2]; if(somethings[0]==somethings[1]) exit(-1); // This line must never run. delete[] somethings;
How to assign function pointer to static function?
if int fn(char ch,int a) is static function then
function pointer type to above static function will be
int (*)(char , int )
Using the class name. In case of non static function we need to use the this pointer.