Thursday, November 19, 2015

Phase IV for BCA III

Sub Name: Object Oriented Programming Using UML & C++
Sub Code: TBC 302
PHASE IV

CONSTRUCTOR
Q1. WAP to demonstrate the use of Different types of Constructors in class NUMBER
NUMBER ()
NUMBER (int a)
NUMBER (int a int b)
NUMBER (NUMBER & A)

Q2. WAP to demonstrate the use of Destructor in class NUMBER
~ NUMBER ()
Q3. Create a class called DISTANCE that has separate member data inches and feet. One constructor should initialize this data to 0, and another should initialize it to fixed values. A member function should display it. The member function should add two objects of type distance passed as arguments. A main ( ) program should create two initialized distance objects, and one that isn’t initialized. Then it should add the two initialized values together, leaving the result in the third distance variable. Finally display the third variable.
INHERITANCE
Q4.  WAP to show multiple inheritance eg, person, faculty and student class.
Q4.  Create two classes DM and DF, which store the value of distances. DM stores distances in meters and centimeters and DF in feet and inches. Write a program that can read values for the class object and add one object of DM with another object of DF. Use a friend function to carry out the addition operation. The object that stores the results may be a DM object or DF object, depending on the units in which results are required. The display should be in the format of feet and inches or meters and centimeters depending on the object on display.
Q5.Write a program to read and display information about employees and managers. Employee is a class that contains employee number, name, address and department. Manager class contains all information of the employee class and list of employees working under manager.
Q6. What is virtual function and how it is used to implement late binding? How will you make a class as an abstract class?
a)WAP to design three classes Figure, Line, Square
Figure:
Name
Color
virtual Getdata()
Disp()
Line:
Name
Color
Getdata()
Disp()
Square:
Name
Color
Side
Area
Getdata()
Disp()
Calc_Area()
Q7. WAP to design three classes Figure, Line, Square.
Figure:
Name
Color
virtual Getdata() =0;
Disp()
Line:
Name
Color
Getdata()
Disp()
Square:
Name
Color
Side
Area
Getdata()
Disp()
Calc_Area()
GENERIC  PROGRAMMING
Q8.  Write a C++ program to create a template function for BUBBLE_SORT and demonstrate sorting of integers and doubles.
Q9.  Write a Function Template for the FIND_MAX function, that finds max of three int, three float and three double value types
Q10.Write a Class Template for the array that can have int, float and double value types as data members.






Phase III qus for BCA III

Sub Name: Object Oriented Programming Using UML & C++
Sub Code: TBC 302
PHASE III

FUNCTION OVERLOADING:
Q 1. Write a program that use function overloading to do the following task-
n  Demonstrate the exact match
n  Demonstrate the integral promotion
n  Demonstrate the ambiguity error
n  Demonstrate the concept of default arguments along with function overloading
Q2. Write a program that use function overloading to do the following task-
n  Find the max. of two numbers
n  Find the max of three numbers
Q3. Write a program that use function overloading to do the following task-
n  Compute xy , where x and y both are of int type. 
n  Compute xy,  where x is float type and y is int type.
Q4. Write a C++ program to create a class called COMPLEX and implement the following overloading functions ADD that return a complex number:
a. ADD(a, s2) – where ‘a’ is an integer (to be added to real part only) and s2 is a complex number
b. ADD(s1, s2) – where s1 and s2 are complex numbers
c. ADD(s1, a) – where ‘a’ is an integer (to be added to real part as well as imaginary part) and s1 is a complex number
Q5. Demonstrate the concept of function overloading among the classes by designing three classes Square, Rectangle, & Circle. All the three classes must have functions getdata(), calc_area(), disp();
Operator Overloading
Q6. Write a complete definition for an overloaded + , - , * operator for the INTEGER class. It should add 2 INTEGER objects. It can solve the following expressions:
A=B*C
A=B*8;
A=B+C-D
A=B-C*D/E
Q7 A class Clock has following members:
Data members:
            Hour of type integer
            Minute of type integer
Second  of type integer
Member function:
            Readtime (int h, int m, int s);
            Showtime ();
            addTime(Clock);
addTime(Clock,Clock);
Write a complete program in C++ to input two different objects FT, ST. Print their sum (assuming 24 hour clock time) by overloading the + operator for class Clock
Q8. Write a complete definition for an overloaded + , - , * operator for the COMPLEX class. It should add 2 COMPLEX objects. It can solve the following expressions:
A=B*C
A=B+C
A=B*8;
A=A*B+C-5*D+8
A=8*B;
If some operation is not possible, mention the reason.
Q9. WAP to add one INTEGER with one FLOAT object, using overloading binary + operator using friend function for FLOAT class and member function for INTEGER class.
Q10. WAP to overload += operator overloading.
Q11. WAP to overload ++ operator overloading.(prefix & postfix)
Q12. WAP to overload -- operator overloading. (prefix & postfix)
Q13. WAP to overload == operator overloading.
Q14. WAP to overload << operator overloading.

Q15. WAP to overload >> operator overloading.

Friday, September 18, 2015

State Diagram

State Diagrams: State Diagrams State diagrams are created during the analysis and design phase to describe the behaviour of nontrivial objects. State diagrams are good for describing the behaviour of one object across several use cases and are used to identify object attributes and to refine the behaviour description of an object.
There are three major components of a state diagram:
State:
A state is a condition in which an object can be at some point during its lifetime, for some finite period of. State diagrams describe all the possible states a particular object can get into and how the objects state changes as a result of external events that reach the object.
States are represented by the values of the attributes of an object.
A state represents a stage in the behaviour pattern of an object, and in a state diagram it is possible to have initial states and final states.
An initial state, also called a creation state, is the one that an object is in when it is first created, whereas a final state is one in which no transitions lead out of.
. In a state diagram:
• A state is represented by a rounded rectangle.
 • A start state is represented by a solid circle.
• A final state is represented by a solid circle with another open circle around it.
Transition
A transition is a progression from one state to another and will be triggered by an event that is either internal or external to the object.
Transitions are the result of the invocation of a method that causes an important change in state.
 A transition is a change of an object from one state (the source state) to another (the target state) triggered by events, conditions, or time. Transitions are represented by an arrow connecting two states.
Transitions can also be labeled with guards (a Boolean expression which evaluates to true or false) inside square brackets, such as [trade accepted]. A guarded transition occurs only if the guard resolves to true. Only one transition can be taken out of a given state. If more than one guard condition is true, only one transition will fire. The choice of transition to fire is nondeterministic if no priority rule is given
The arrows in state diagram represent transitions, progressions from one state to another.
Event: Is something that occurs at a point of time.
Events are internal or external factors influencing the system.
Event causes the transitions

State diagrams are used to model states and also events operating on the system. 







Wednesday, September 9, 2015

Translators(MCA I)

Translators
Assembler
An assembler translates assembly language into machine code. Assembly language consists of mnemonics for machine opcodes so assemblers perform a 1:1 translation from mnemonic to a direct instruction. For example:
LDA #4 converts to 0001001000100100
Conversely, one instruction in a high level language will translate to one or more instructions at machine level.
Advantages of using an Assembler:
·         Very fast in translating assembly language to machine code as 1 to 1 relationship
·         Assembly code is often very efficient (and therefore fast) because it is a low level language
·         Assembly code is fairly easy to understand due to the use of English-like mnemonics

Disadvantages of using Assembler:
·         Assembly language is written for a certain instruction set and/or processor
·         Assembly tends to be optimised for the hardware it's designed for, meaning it is often incompatible with different hardware
·         Lots of assembly code is needed to do relatively simple tasks, and complex programs require lots of programming time

Compiler
A Compiler is a computer program that translates code written in a high level language to a lower level language, object/machine code. The most common reason for translating source code is to create an executable program (converting from a high level language into machine language).
Advantages of using a compiler
·         Source code is not included, therefore compiled code is more secure than interpreted code
·         Tends to produce faster code than interpreting source code
·         Produces an executable file, and therefore the program can be run without need of the source code

Disadvantages of using a compiler
 Object code needs to be produced before a final executable file, this can be a slow process
 The source code must be 100% correct for the executable file to be produced

Interpreter
An interpreter program executes other programs directly, running through program code and executing it line-by-line. As it analyses every line, an interpreter is slower than running compiled code but it can take less time to interpret program code than to compile and then run it — this is very useful when prototyping and testing code. Interpreters are written for multiple platforms, this means code written once can be run immediately on different systems without having to recompile for each. Examples of this include flash based web programs that will run on your PC, MAC, games console and Mobile phone.
Advantages of using an Interpreter
·         Easier to debug(check errors) than a compiler
·         Easier to create multi-platform code, as each different platform would have an interpreter to run the same code
·         Useful for prototyping software and testing basic program logic
Disadvantages of using an Interpreter
·         Source code is required for the program to be executed, and this source code can be read making it insecure
·         Interpreters are generally slower than compiled programs due to the per-line translation method


Computer Language(MCA 1)

Language:Just as humans use language to communicate, and different regions have different languages, computers also have their own languages that are specific to them.
Different kinds of languages have been developed to perform different types of work on the computer. Basically, languages can be divided into two categories according to how the computer understands them.
Two Basic Types of Computer Language
·         Low-Level Languages: A language that corresponds directly to a specific machine
·         High-Level Languages: Any language that is independent of the machine

Low-Level Languages

Low-level computer languages are either machine codes or are very close them. A computer cannot understand instructions given to it in high-level languages or in English. It can only understand and execute instructions given in the form of machine language i.e. binary. There are two types of low-level languages:
·         Machine Language: a language that is directly interpreted into the hardware
·         Assembly Language: a slightly more user-friendly language that directly corresponds to machine language
1.   Machine Language
Machine language is the lowest and most elementary level of programming language and was the first type of programming language to be developed. Machine language is basically the only language that a computer can understand and it is usually written in hex.
In fact, a manufacturer designs a computer to obey just one language, its machine code, which is represented inside the computer by a string of binary digits (bits) 0 and 1. The symbol 0 stands for the absence of an electric pulse and the 1 stands for the presence of an electric pulse. Since a computer is capable of recognizing electric signals, it understands machine language.
Advantages:
·        Machine language makes fast and efficient use of the computer.
·        Machine language makes fast and efficient use of the computer.
·        Machine language makes fast and efficient use of the computer.
·        It requires no translator to translate the code. It is directly understood by the computer.
Disadvantages
·        All operation codes have to be remembered.
·        All memory addresses have to be remembered.
·        It is hard to amend or find errors in a program written in the machine language.

2.   Assembly Language
Assembly language was developed to overcome some of the many inconveniences of machine language. This is another low-level but very important language in which operation codes and operands are given in the form of alphanumeric symbols instead of 0’s and l’s.
These alphanumeric symbols are known as mnemonic codes and can combine in a maximum of five-letter combinations e.g. ADD for addition, SUB for subtraction, START, LABEL etc. Because of this feature, assembly language is also known as ‘Symbolic Programming Language.'
This language is also very difficult and needs a lot of practice to master it because there is only a little English support in this language. Mostly assembly language is used to help in compiler orientations. The instructions of the assembly language are converted to machine codes by a language translator and then they are executed by the computer.
Advantages:
·        Assembly language is easier to understand and use as compared to machine language
·        It is easy to locate and correct errors.
·        It is easily modified.
Disadvantages:
·        Like machine language, it is also machine dependent/specific.
·        Since it is machine dependent, the programmer also needs to understand the hardware.

High-Level Languages

High-level computer languages use formats that are similar to English. The purpose of developing high-level languages was to enable people to write programs easily, in their own native language environment (English).
High-level languages are basically symbolic languages that use English words and/or mathematical symbols rather than mnemonic codes. Each instruction in the high-level language is translated into many machine language instructions that the computer can understand.
Advantages:
·        High-level languages are user-friendly
·        They are similar to English and use English vocabulary and well-known symbols
·        They are easier to learn.
·        They are easier to maintain
·        They are problem-oriented rather than 'machine'-based
·        A program written in a high-level language can be translated into many machine languages and can run on any computer for which there exists an appropriate translator
·        The language is independent of the machine on which it is used i.e. programs developed in a high-level language can be run on any computer text
Disadvantages:
·        A high-level language has to be translated into the machine language by a translator, which takes up time
·        The object code generated by a translator might be inefficient compared to an equivalent assembly language program




MCA I: Assignment 1

Q1. Write a note on history of C language.
Q2. Define the term of translators. What are the different types of translators?
Q3. Write a note on the following:
A.      Low Level language
B.      Middle Level Language
C.      High Level Language
Q4. What are the different types of operators? What do you mean by precedence and associativity of an operator? Explain the use of each using examples.
[ +,         -,             *,           /,            %,         
 =,           <,           <=,        >,            >=,         ==,         !=,         
?:,          
sizeof()
++,         --


Q5. Write a short note on Keyword, Data Type & Variable.