Anda di halaman 1dari 9

www.ignousolvedassignments.com Connect on Facebook : http://www.facebook.com/pages/IgnouSolvedAssignmentscom/346544145433550 Subscribe and Get Solved Assignments Direct to your Inbox : http://feedburner.google.com/fb/a/mailverify?

uri=ignousolvedassignments_com

Course Code Course Title Assignment Number

: : :

CS 72 C++ and Object Oriented Programming BCA (6)-72/Assignment/ 2012

Maximum Marks
Last Date of Submission

:
:

100 (Weightage 25%)


30th April, 2012/30th October, 2012

There are seven questions in this Assignment. Answer all the questions. You may use illustrations and diagrams to enhance your explanations. Please go through the guidelines regarding assignments given in the Programme Guide for the format of presentation. Answer to each part of the question should be confined to about 300 words.

1)

Create a class named employee that stores the employee ID, employee name, date of birth, date of joining, designation and department. The class should include a constructor that initializes an object of that class, a member function that modifies the value of department and designation and a function to print all the information of the class. Explain the features of the term Class and Object in the context of object oriented programming in the context of the class you have created. List the private and public members (data members as well as member functions) for the class employee. Define the data types of member variables using C++ and create few objects of the class.

Answer Code #include <iostream> #include <iomanip> #include <string> class Employee { private: char *Name; //Set them as pointers... int IdNumber;

www.ignousolvedassignments.com char *Department; char *Position; public: void setName(char Name); void setDepartment(char Dept); void setIdNumber(int ID); void setPosition(char POS); } Employee::Employee() { Name=" "; IdNumber=0; Department=" "; Position=" ";

www.ignousolvedassignments.com }; void Employee::setName(const char* Name) { Name = Name; } void Employee::setIdNumber(int ID) { IdNumber = ID; } void Employee::setDepartment(const char* Dept) //WTF? why integer? Keep as character string! { Department = Dept; } void Employee::setPosition (const char* POS) //Same thing here! { Position = POS; } char Employee::getName() //const //What are these for? { return Name; } int Employee::getIdNumber() //const //What are these for? Plus, get your return types right! { return IdNumber; } char Employee::getDepartment() //const //What are these for? Plus, get your return types right! { return Department; } char Employee::getPosition() //const //What are these for? Plus, get your return types right! { return Position; } int main() {

Output Employee SusanMeyer(), MarkJones(), JoyRogers(); SusanMeyer.setPosition("Vice President"); //etc.. for all the other guys...

cout << " NAME ID NUMBER DEPARTMENT cout << "-------------------------------------------\n";

POSITION\n";

return 0;

www.ignousolvedassignments.com }

(((((( I am Not entirely Sure that this code works I have found 5 errors in this code, please use at your own risk , and I have not written about the datatypes, You can easily write it down yourself by seeing what are the int and str variables used in the code ))))
2) Create another class Manger, which is a derived class of the class employee. A manager may be working in a department but managing a different department. Thus, this class has extra information- Manages Department. Create the class managers as a sub class of class employee. You must use the following concepts while deriving the classes (Please also write the appropriate main( ) to demonstrate the concepts)

(a) Overloaded Constructors (b) Encapsulation (c) Inheritance (d) Polymorphism Explain how and where in your classes - employee and managers the concepts listed above have been demonstrated.

(((( Please Create this yourself it's the same code which is being used for 1st answer with little modifications))))
3 ) What are the advantages of using UML? Create the class diagram for an Office having classes - Employee, Manager, Department, Projects. Make suitable assumptions, if any.

Advantages of using UML UML breaks the complex system into discrete pieces that can be understood easily. Handover the system to new team becomes easier. Complex system can be understood by the disparate developers who are working on different platforms. UML model is not a system or platform specific. It unifies all disparate developers under one roof. Person class Department Class Manager Class Collaborator class Project Class

www.ignousolvedassignments.com

4)

Explain the usage of the following C++ operators with the help of example program(s).

(a) Bitwise AND A bitwise operation operates on one or more bit patterns or binary numerals at the level of their individual bits. It is a fast, primitive action directly supported by the processor, and is used to manipulate values for comparisons and calculations. On simple low-cost processors, typically, bitwise operations are substantially faster than division, several times faster than multiplication, and sometimes significantly faster than addition (b) Explicit Typecasting Traditional explicit type-casting allows to convert any pointer into any other pointer type, independently of the types they point to. The subsequent call to member result will produce either a run-time error or a unexpected result. (c) Array of Pointer A pointer is a variable that contains the memory location of another variable. The values you assign to the pointers are memory addresses of other variables. So an Array with pointers such as these are called array of pointers ( d) Arithmetic if operator Uses short-circuit evaluation to conditionally return one of two values. The If operator can be called with three arguments or with two arguments.

www.ignousolvedassignments.com 5 ) What is call by value in the context of C++? Explain with the help of an example. What is the problem associate with the swap function that tries to exchange the values of two variables using the third variable and using call by value in a calling program. What are the two different ways you can remedy the problem such that swap function is able to change the values of two variables in the calling function. Passing a variable by value makes a copy of the variable before passing it onto a function. This means that if you try to modify the value inside a function, it will only have the modified value inside that function. One the function returns, the variable you passed it will have the same value it had before you passed it into the function. This is known as call by value, example: #include <stdio.h> #include <stdlib.h> void printtotal(int total); void addxy(int x, int y, int total); void subxy(int x, int y, int *total); void main() { int x, y, total; x = 10; y = 5; total = 0; printtotal(total); addxy(x, y, total); printtotal(total); subxy(x, y, &total); printtotal(total);

}
void printtotal(int total) { printf("Total in Main: %dn", total); } void addxy(int x, int y, int total) { total = x + y; printf("Total from inside addxy: %dn", total); } void subxy(int x, int y, int *total) { *total = x - y; printf("Total from inside subxy: %dn", *total); }
void swap ( vector<T,Allocator>& vec );

Swap content
Exchanges the content of the vector by the content of vec, which is another vector of the same type. Sizes may differ. After the call to this member function, the elements in this container are those which were in vec before the call, and the elements of vec are those which were in this. All iterators, references and pointers remain valid for the swapped vectors. Notice that a global algorithm function exists with this same name, swap, and the same behavior.

www.ignousolvedassignments.com

6) Write a template class "circularqueue" in C++. The class should have functions for adding an element in the rear and removing an element from the front of the circular queue. The class should have additional functions for Queuefull and queueempty. Use this template to create a circularqueue of integer values with maximum size of 10 elements. Make suitable assumptions, if any.
Template H file code

// templateq.h #ifndef TEMPLATEQ_H #define TEMPLATEQ_H #include <iostream> #include <new> #include <cstddef> using namespace std; class FullTemplateQ // Exception class {}; class EmptyTemplateQ // Exception class {}; template<class SomeType> // Node template class struct QueueNode { SomeType data; // Data stored in queue node QueueNode<SomeType>* nextPtr; // Pointer to next queue node }; template<class SomeType> // Circular queue template class class TemplateQ { private: QueueNode<SomeType>* rearPtr; // Pointer to rear of queue QueueNode<SomeType>* frontPtr; // Pointer to front of queue void PrintNext(QueueNode<SomeType>* tempPtr) const; // Print trailing items public: TemplateQ(); // Default constructor ~TemplateQ(); // Destructor deallocates every node void Enqueue(SomeType newData); // Adds newdata node to rear of queue SomeType Dequeue(); // Removes data node from front of queue, // returning the stored data bool IsFull() const; // Returns true if queue is full, // false otherwise bool IsEmpty() const; // Returns true if queue is empty, // false otherwise int Size() const; // Returns the number of items in queue void ForwardPrint() const; // Prints queue, front to rear void ReversePrint() const; // Prints queue, rear to front

www.ignousolvedassignments.com }; #include "templateq.cpp" // Very Important!! Do not delete!! #endif Template q File Code //templateq.cpp #ifdef TEMPLATEQ_H TEMPLATEQ_H #include <iostream> template <class someType> TemplateQ<someType>::TemplateQ() { rearPtr = NULL; frontPtr = NULL; cout << "Instantiation successful!" << endl; } template <class someType> TemplateQ<someType>::~TemplateQ(){ cout << "Destruction successful!" << endl; } #endif

Driver Program File // driver program #include "templateq.h" #include <iostream> using std::cin; using std::cout; using std::endl; int main(){ TemplateQ<int> tq; cin.ignore(INT_MAX, '\n'); cin.get(); return 0; }

7. Create a class LONGBINARYINTEGER that stores only binary digits (0 or 1) in a string of arbitrary length (the string is in the order of lowest significant bit to highest significant bit that is first element is lowest significant bit). The string has a constructor that makes sure that String has only binary digits. The class also has a copy constructor, and an overloaded + operator. The overloaded + operator adds two stings bit by bit taking care of the carry bit from the previous bit addition. Design and implement the class using C++. Write appropriate main( ) function to demonstrate the functionality of the class.

www.ignousolvedassignments.com

Hint : The string is in long integer you have to change it into binary digits ((( Please Solved this yourself )))

For More Ignou Solved Assignments Please Visit -

www.ignousolvedassignments.com

Anda mungkin juga menyukai