CS-72x - hphany.com

oatmealbrothersΛογισμικό & κατασκευή λογ/κού

18 Νοε 2013 (πριν από 4 χρόνια και 7 μήνες)

100 εμφανίσεις

Visit for more solved assignment:


Presented by


Course Code


CS 72

Course Title


C++ and Object Oriented Programming

Assignment Number


BCA (6)
72/Assignment/ 2012

Maximum Marks


100 (Weightage 25%)

Last Date of Submission



April, 201

October, 2012

There are seven questions in thi
s 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


Create a class named employee that stores the employee ID, employee n
ame, 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 inform
ation 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.

(8 Marks)


#include <iostream>

ude <iomanip>

#include <string>

class Employee



char *Name; //Set them as pointers...

int IdNumber;

char *Department;

char *Position;


void setName(char Name);

void setDepartment(char Dept);

void setIdNumber(int ID);

void setPosition(char



Visit for more solved assignment:


Name=" ";


Department=" ";

Position=" ";


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, ge
t your return types right!


return Position;

} int main()



Employee SusanMeyer(), MarkJones(), JoyRogers();

SusanMeyer.setPosition("Vice President");

//etc.. for all the other guys...


cout <<

return 0;



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

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):

Visit for more solved assignment:


aded Constructors







Explain how and where in your classes

employee and managers the concepts listed
above have been demonstrated.

(28 Marks)


Please create this yourself

it’s the same code which is being

used for 1st answer with little


What are the advantages of using UML? Create the class diagram for an Office having

Employee, Manager, Department, Projects. Make suitable assumptions, if any.

(8 Marks)


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


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


Bitwise AND


Explicit Typecasting


Array of Pointer


Arithmetic if operator

(8 Marks)


(a) Bitwise AND

The & (AND) operator compares two values, and returns a value that has its bits set if, and only
if, the
two values being compared both have their corresponding bits set. The bits are compared
using the following table

1 & 1 == 1

1 & 0 == 0

0 & 1 == 0

Visit for more solved assignment:

0 & 0 == 0

An ideal use for this is to set up a mask to check t
he values of certain bits. Say we have a BYTE
that contains some bit flags, and we want to check if bit four bit is set.

BYTE b = 50;

if ( b & 0x10 )

cout << "Bit four is set" << endl;


cout << "Bit four is clear" << endl;

This would result
in the following calculation



& 00010000

& 0x10




So we see that bit four is set.


Explicit Typecasting

When we are performing any operation between variables the variable will be converted
automatically from one data type to another. But when the user want to convert data from one
form to another then this type of conversion is known as explicit type casting. Explicit type
casting can be achieved by writing the conversion data type before th
e variable or expression in

Type casting operators allow you to convert a datum of a given type to another. There are several
ways to do this

in C++. The simplest one, which has been inherited from the C language, is to
precede the expression to


converted by the new type enclosed between parentheses (()):

int i;

float f = 3.14;

i = (int) f;

The previous code converts the float number 3.14 to an integer value (3), the remainder is lost.
Here, the

typecasting operator was (int). Another way to

do the same thing in C++ is using the
functional notation:

preceding the expression to be converted by the type and enclosing the
expression between parentheses:

i = int ( f );

Both ways of type casting are valid in 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 (or other pointers). A running
program gets a certain space in the main memory.

Visit for more solved assignment:

Syntax of declari
ng a pointer:

data_type_name * variable name

First of all, specify the data type of data stored in the location, which is to identified by the
pointer. The asterisk tells the compiler that you are creating a pointer variable. Then specify the
name of v

(d) Arithmetic if operator

The arithmetic if operator (?:) is also known as the conditional operator, and it is C++’s only
ternary operator (it takes 3 operands). The ?: operator provides a shorthand method for doing a
particular type of if/else


If/else statements in the following form:

if (condition)

x = some value


x = some other value

can be rewritten as:

x = (condition) ? some value : some other value;

For example, to put the larger of values x and y in variable z,

we could write this:

if (x > y)

z = x;


z = y;

Or this:

z = (x > y) ? x : y;


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 func

(8 Marks)


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
Visit for more solved assignment:

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;


addxy(x, y, total);


subxy(x, y, &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


printf("Total from inside subxy: %dn", *total);


void swap ( vector<T,Allocator>& vec );

Swap content

Exchanges th
e 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

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.


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 valu
es with maximum size of 10 elements. Make suitable
assumptions, if any.

(20 Marks)


Visit for more solved assignment:

Template H file code

// templateq.h



#include <iostream>

#include <new>

#include <cstddef>

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



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


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 fr
ont 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

ForwardPrint() const; // Prints queue, front to rear

void ReversePrint() const; // Prints queue, rear to front


#include "templateq.cpp" // Very Important!! Do not delete!!


Template q File Code




#include <iostream>

template <class someType>


Visit for more solved assignment:


earPtr = NULL;

frontPtr = NULL;

cout << "Instantiation successful!" << endl;


template <class someType>


cout << "Destruction successful!"
<< endl;



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, '


return 0;



Create a class LONGBI
NARYINTEGER 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
ure 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 u
sing C++.
Write appropriate main( ) function to demonstrate the functionality of the class.

(20 Marks)

coming soon