Skip to main content

Posts

Showing posts from March, 2011

Problems Related to Class and Inheritance

Problem #1: This program contains some error(s), can you spot which line(s) contains error(s)? 1 // Problems No.1 2 // Related to Inheritance 3 #include 4 5 // base class 6 class base 7 { 8 int a; 9 10 public: 11 void seta(int num){a=num;} 12 }; 13 14 // derived class 15 class derived:public base 16 { 17 int b; 18 19 public: 20 void setb(int num){b=num;} 21 22 void show() 23 { 24 cout< 4 5 // base class 6 class base 7 { 8 protected: 9 int a; 10 11 public: 12 void seta(int num){a=num;} 13 }; 14 15 // derived class 16 class derived:protected base 17 { 18 protected: 19 int b; 20 21 public: 22 void setb(int num){b=num;} 23 void show() 24 { 25 cout< 4 5 // base class (1) 6 class

Inline Functions and their Uses

It’s a good practice to divide the program into several functions such that parts of the program don’t get repeated a lot and to make the code easily understandable. We all know that calling and returning from a function generates some overhead. The overhead is sometimes to such an extent that it makes significant effect on the overall speed of certain complex and function-oriented programs. In most cases, we have only a few functions that have extensive use and make significant impact on the performance of the whole program. Not using functions is not an option, using function-like macros is an option, but there is a better solution, to use Inline Functions. Yes, like it sounds, inline functions are expanded at the place of calling rather than being “really called” thus reducing the overhead. It means wherever we call an inline function, compiler will expand the code there and no actual calling will be done. Member functions of classes are generally made inline as in many case

ER diagram

1. Prepare an E-R diagram for a real estate firm that lists property for sale. The following describes the organization: • The firm has a number of sales offices in several states. • Each sales office is assigned one or more employees. An employee must be assigned to only one sales office. • For each sales office, there is always one employee assigned to manage that office. An employee may manage only one sales office to which he/she is assigned. • The firm (sales office) lists property for sale. • Each unit of property must be listed with one (and only one) of the sales offices. A sales office may have any number of properties listed, or may have no properties listed. • Each unit of property has one or more owners. An owner may have one or more units of property.

Templates

TEMPLATES C++ gives us the facility to write a common function that is independent of the data type but which embodies the common set of instruction which could be applied on any data type. This has some advantages, like ease of code development and code maintenance. This could be accomplished with the help of templates. Inside the templates we can have some or all data types unspecified. (Any data type is accepted.) Templates could be created for individual function or a class. Template function is called generic function and class is called generic class. GENERIC FUNCTION The syntax for creating a template for generic function is as follows: Template Return_type function_name (T arg1, T arg2, T arg3……….) { // function statements } It should begin with the keyword template. Ttype is the placeholder name for a data type used by th function. Prog1: #include template void swapdata(X & a, X & b) { X temp; t

complex no

complex no usig operator overloading #include #include class complex { float r,l; public: void setdata() { cout <<"Enter complex number"; cin >>r>>l; } void show() { cout < } complex operator +(complex p) { complex temp; temp.r=r+p.r; temp.l=l+p.l; return(temp); } }; void main() { clrs r complex c1,c2,c3; c1.setdata(); c2.setdata(); c3=c1+c2; c3.show(); gecth(); }

OPERATOR OVERLOADING

simple example of operator overloading #include #include class multiply { int a,b; public: void setdata() { cout <<"Enter 2 numbers"; cin >>a>>b; } void show() { clrscr(); cout <<"a="< >k; m*k; m.show(); getch(); }
Assingment NO 1 THE USE OF CSS(CACCADING STYLE SHEET) BIODATA MANISH RAJ B.Sc C.A.(Part-2) 20 Golmuri SAVE WITH info.XML OPEN A NEW NOTEPAD : root { background-color:orange; } resume { display:block; font-style:bold; font-style:italic; color:yellow; font-size:60pt; } name { display:block; font-style:bold; font-style:italic; color:red; font-size:60pt; } education { display:block; font-style:bold; font-style:italic; color:blue; font-size:50pt; } age { display:block; font-style:bold; font-style:italic; color:green; font-size:40pt; } address { display:block; font-style:bold; font-style:italic; color:brown; font-size:30pt; } save with info.css

USE OF BASE CLASS

A program to show the use of vitual base class #include #include class A { protected: int a; public: void seta() { a=10; } }; class B:virtual public A { protected: int b; public: void setb() { b=20; } }; class C:virtual public A { protected: int c; public: void setc() { c=30; } }; class D:public B,public C { private: int d; public: void setd() { d=40; } void display() { cout<<"The Value Of A is="<

USE OF BASE CLASS

A program to show the use of vitual base class #include #include class A { protected: int a; public: void seta() { a=10; } }; class B:virtual public A { protected: int b; public: void setb() { b=20; } }; class C:virtual public A { protected: int c; public: void setc() { c=30; } }; class D:public B,public C { private: int d; public: void setd() { d=40; } void display() { cout<<"The Value Of A is="<

Leadership Skills

Yesterday my father advised me to read Develop your leadership skills . I started reading today and I couldn't stop myself in between. It is a great book written by John Adair. Leadership skills have now been universally recognised as a key skill It is possible to develop your own abilities as a leader. All this book is about How to do that. I just want to share few points that I found intresting about leadership Nobody can teach you leadership. It is something you have to learn. You learn principally from experience. But experience or practice has to be illuminated by principles or ideas. A) PERSONALITY AND CHARACTER : Personality and Character are important qualities of leadership. A Leader should possess, exemplify and perhaps even personify the qualities expected or required in his working group. Without it he will lack credibility. (Incidentally, here is one of the first differences between leaders and managers: the latter can be appointed over others in a hierarchy rega