CS301 VU Current Assignment No. 1 Spring 2013 Solution

CS301 VU Current Assignment No. 1 Spring 2013 Solution

Assignment No. 01 SEMESTER Spring 2013 CS301‐ Data Structures
Total Marks: 20
Due Date: 25/04/2013

Assignment:

We know that in linked list we have one value and one pointer (to hold the memory address of next node). Note that it is not compulsory to have only one value. There can be more than one value in one node but the pointer will remain one.

Write a C++ program to implement linked list data structure. In this problem every node should have six values, the name of node and a pointer. Your program should prompt the user to enter total number of nodes in the list. After this give the name to node and save 6 different values in node. Process should be repeated for each node.

After entering values of all the nodes, sum the values in each node and sort the list in ascending order (on the basis of sum calculated in each node) i.e. node with smallest sum comes first and node with largest sum comes last.

Note: Values within a single node should not duplicate. If a user tries to enter any duplicate value WITHIN A NODE then show a warning message and ask user to enter value again.

The diagram given below is showing the sorted list.

IMAGE

Solution Guidelines:
1. First understand the code given in handouts about linked list.
2. To save six different values in one node you can use array as data member of Node class.
3. Get the sum of six values and on comparison of sum of different nodes sort the list.
4. To get the idea about exact output of program, see Demo.wmv file attached with assignment file.

SOLUTION IDEA:

Lecture no 3 and 4 very important for this assignment.

A linked list is a popular data structure to store data in sequential order. Meanwhile, linked list structure allow following operations which overcomes limitation of array: for example
1. Retrieve an element from list.
2. Insert a new element to the list.
3. Delete an element from the list.
4. Find how many elements are in the list.
5. Find a specific element is in the list.
6. Find if this list is empty.

……………

#include <iostream>
#include <conio.h>
using namespace std;
class Node{
public:
void set_next(Node* next_node){Next_Node = next_node;}
Node * get_next(){return Next_Node;}
char * get_name(){return nod_name;}
void set_objects(int,int);
void set_name(char*);
int get_objects(int);
void set_sum(int sums){sum = sums;}
int get_sum(){return sum;}
~Node(){};
private:
int sum;
char *nod_name;
int objects[6];
Node * Next_Node;
};
void Node::set_name(char* name){
nod_name = new char[strlen(name+1)];
strcpy(nod_name,name);
}
void Node::set_objects(int obj,int indux)
{
objects[indux] = obj;
}
int Node::get_objects(int indux)
{
return objects[indux];
}
class List{
public:
List();
void sort(Node*,int);
void display(int);
void get_input(int,Node*);
int get(int);
void add(int[],Node*);
private:
int size;
Node * Head_Node;
Node * Current_Node;
Node * Last_Current_Node;
};
List::List()
{
size = 0;
Head_Node = new Node();
Head_Node->set_next(NULL);
Current_Node = NULL;
Last_Current_Node = NULL;
}
void List::sort(Node * sort_node, int number_nodes)
{
char temp_name[25];
Current_Node = Head_Node;
int * sum = new int[number_nodes];
for(int i=0;i<number_nodes;i++)
{
sum[i] = 0;
if(Current_Node != NULL)
{
for(int a=0;a<6;a++)
{
sum[i] += this->Current_Node->get_objects(a);
}
}
Current_Node->set_sum(sum[i]);
Current_Node = Current_Node->get_next();
}
Current_Node = Head_Node;
Last_Current_Node = Head_Node->get_next();
int temp = 0;
for(int i=0;i<number_nodes;i++)
{
for(int a=0;a<number_nodes;a++)
{
if(Current_Node != NULL && Last_Current_Node != NULL)
{
if(Current_Node->get_sum() < Last_Current_Node->get_sum())
{
temp = Current_Node->get_sum();
strcpy(temp_name , Current_Node->get_name());
Current_Node->set_sum(Last_Current_Node->get_sum());
Current_Node->set_name(Last_Current_Node->get_name());
Last_Current_Node->set_sum(temp);
Last_Current_Node->set_name(temp_name);
}
Last_Current_Node = Last_Current_Node->get_next();
}
else
{
break;
}
}
Last_Current_Node = Head_Node;
Current_Node = Current_Node->get_next();
}
}
void List::display(int number_nods)
{
Current_Node = Head_Node;
if(Current_Node != NULL)
{
cout<<”List Size = “<<size<<endl;
for(int a=0;a<number_nods;a++)
{
cout<<’\n’<<endl;
cout<<’\t’<<”Elements Of: “<<a+1<<’\t’<<Current_Node->get_name()<<endl;
Current_Node = Current_Node->get_next();
}
}
}
void List::get_input(int number_nod,Node * Nodes)
{
int f = 0;
char arrs[25];
for(int i=0;i<number_nod;i++)
{
int arr[6] = {0};
cout<<”Enter The Name OF the Node: “;
cin>>arrs;
Nodes[i].set_name(arrs);
for(int a=0;a<6;a++)
{
f = 0;
cout<<”enter Value “<<a+1<<”: “;
cin>>arr[a];
for(int j=0;j<6;j++)
{
if(arr[a] == arr[j])
{
f++;
}
}
if(f > 1)
{
cout<<arr[a]<<” Duplicated value is not allowed “<<endl;
a–;
continue;
}
}
cout<<endl;
cout<<”Node Value Finshed”<<endl<<endl;
this->add(arr,&Nodes[i]);
}
}
int List::get(int Indux)
{
return Current_Node->get_objects(Indux);
}
void List::add(int objests[],Node * nodss)
{
for(int i=0;i<6;i++)
{
nodss->set_objects(objests[i],i);
}
if(Current_Node == NULL)
{
nodss->set_next(NULL);
Head_Node->set_next(nodss);
Last_Current_Node = Head_Node;
Current_Node = nodss;
Head_Node = Current_Node;
}
else
{
nodss->set_next(Current_Node->get_next());
Current_Node->set_next(nodss);
Last_Current_Node = Current_Node;
Current_Node = nodss;
}
size++;
}
int main()
{
List list;
int number_nods = 0;
cout<<”How many Nodes You want to Create ?? “;
cin>>number_nods;
Node * Nodes = new Node[number_nods];
list.get_input(number_nods,Nodes);
list.sort(Nodes,number_nods);
list.display(number_nods);
delete [] Nodes;
}

…………….

#include <iostream>
#include <conio.h>
using namespace std;
class Node{
public:
void set_next(Node* next_node){Next_Node = next_node;}
Node * get_next(){return Next_Node;}
char * get_name(){return nod_name;}
void set_objects(int,int);
void set_name(char*);
int get_objects(int);
void set_sum(int sums){sum = sums;}
int get_sum(){return sum;}
~Node(){};
private:
int sum;
char *nod_name;
int objects[6];
Node * Next_Node;
};
void Node::set_name(char* name){
nod_name = new char[strlen(name+1)];
strcpy(nod_name,name);
}
void Node::set_objects(int obj,int indux)
{

objects[indux] = obj;
}
int Node::get_objects(int indux)
{
return objects[indux];
}

class List{
public:
List();
void sort(Node*,int);
void display(int);
void get_input(int,Node*);
int get(int);
void add(int[],Node*);
private:
int size;
Node * Head_Node;
Node * Current_Node;
Node * Last_Current_Node;
};
List::List()
{
size = 0;
Head_Node = new Node();
Head_Node->set_next(NULL);
Current_Node = NULL;
Last_Current_Node = NULL;
}
void List::sort(Node * sort_node, int number_nodes)
{
char temp_name[25];
Current_Node = Head_Node;
int * sum = new int[number_nodes];
for(int i=0;i<number_nodes;i++)
{
sum[i] = 0;
if(Current_Node != NULL)
{
for(int a=0;a<6;a++)
{
sum[i] += this->Current_Node->get_objects(a);
}
}
Current_Node->set_sum(sum[i]);
Current_Node = Current_Node->get_next();

}
Current_Node = Head_Node;
Last_Current_Node = Head_Node->get_next();
int temp = 0;
for(int i=0;i<number_nodes;i++)
{

for(int a=0;a<number_nodes;a++)
{

if(Current_Node != NULL && Last_Current_Node != NULL)
{

if(Current_Node->get_sum() < Last_Current_Node->get_sum())
{

temp = Current_Node->get_sum();
strcpy(temp_name , Current_Node->get_name());
Current_Node->set_sum(Last_Current_Node->get_sum());
Current_Node->set_name(Last_Current_Node->get_name());
Last_Current_Node->set_sum(temp);
Last_Current_Node->set_name(temp_name);

}
Last_Current_Node = Last_Current_Node->get_next();
}
else
{
break;
}

}
Last_Current_Node = Head_Node;
Current_Node = Current_Node->get_next();

}
}
void List::display(int number_nods)
{
Current_Node = Head_Node;
if(Current_Node != NULL)
{
cout”List Size = “sizeendl;
for(int a=0;a<number_nods;a++)
{
cout’\n’endl;
cout’\t’”Elements Of: “a+1′\t’Current_Node->get_name()endl;

Current_Node = Current_Node->get_next();
}
}
}
void List::get_input(int number_nod,Node * Nodes)
{
int f = 0;
char arrs[25];
for(int i=0;i<number_nod;i++)
{
int arr[6] = {0};
cout”Enter The Name OF the Node: “;
cin>>arrs;
Nodes[i].set_name(arrs);
for(int a=0;a<6;a++)
{
f = 0;
cout”enter Elements “a+1″: “;
cin>>arr[a];
for(int j=0;j<6;j++)
{
if(arr[a] == arr[j])
{

f++;

}
}
if(f > 1)
{
coutarr[a]” Dublicated”endl;
a–;
continue;
}

}
coutendl;
cout”Node Value Finshed”endlendl;
this->add(arr,&Nodes[i]);
}

}

int List::get(int Indux)
{
return Current_Node->get_objects(Indux);
}
void List::add(int objests[],Node * nodss)
{

for(int i=0;i<6;i++)
{
nodss->set_objects(objests[i],i);
}
if(Current_Node == NULL)
{

nodss->set_next(NULL);
Head_Node->set_next(nodss);
Last_Current_Node = Head_Node;
Current_Node = nodss;
Head_Node = Current_Node;

}
else
{
nodss->set_next(Current_Node->get_next());
Current_Node->set_next(nodss);
Last_Current_Node = Current_Node;
Current_Node = nodss;
}
size++;
}
int main()
{
List list;
int number_nods = 0;
cout”How many Nodes You want to Create: “;
cin>>number_nods;
Node * Nodes = new Node[number_nods];
list.get_input(number_nods,Nodes);
list.sort(Nodes,number_nods);
list.display(number_nods);
delete [] Nodes;
_getch();
}

 

Advertisements

VU CS101 Current Assignment No. 1 Spring 2013 Solution

CS101 VU Current Assignment No. 1 Spring 2013 Solution

Assignment No. 01
Semester: Spring 2013
Introduction to Computing-CS101

Total Marks: 20

Due Date: 02-05-2013

Fill the empty columns for the following truth table where A, B and C are three binary inputs in the truth table.

Inputs Output Output Output Output Output
A B C (A´. B´)´ (A´+B)´ (B+C)´ (A. B)´⊕(B+C´) (A⊕ B). (B+C)
1
1
1 1
1
1 1
1 1
1 1 1

SOLUTION:

Agr A true ho to A’ false ho ga or agr A false hy to A’ true ho ga.
(A.B) agr 2no true hn to true or agr 2no false hn ya aik bhi false ho to false ho ga.
(A’+B’) Agr 2no false hn to false or agr 2no true ya aik bhi true ho to true.
(A⊕B) Agr 2no true to false and agr 2no false to phr bhi false or agr aik bhi true to true ho ga.

Q1 Solution:

Virtual University CS301 VU Current Assignment No. 2 Spring 2013 Solution

CS301 VU Current Assignment No. 2 Spring 2013 Solution

Assignment – Marks: 20 – Last Date 2 May 2013

Suppose three movies (Harry Potter, English Vinglish and Tekken) are on display in a cinema. Three different  counters are distributing tickets for each movie. To purchase a particular movie ticket, you are required to standing the respective movie counter queue.

Considering the above scenario, write a C++ program which asks a user to choose the movie for which he/she would like to purchase a Ticket. While choosing the movie ticket, user should be asked to enter his/her social group [F for female, M for male and K for kids].

The required program functionalities should be:

> Take input for all the three movies.
> Display the total number of visitors for each movie.
> Display total revenue of cinema and total revenue of each movie (Suppose price of one ticket is 650/-).
> Display the best business earning movie of the cinema.
> Check the popularity of each movie amongst social groups (females, males or kids).

Solution Guidelines:

1) To purchase the movie ticket, viewer must have to stand in the queue. The length of the queue can vary so you have to implement queue as link list.

2) Create a class named Viewer (Node class); this class should create a node for each ticket. This class should define two private data members, social group and Next pointer. A constructor, getter and setter functions for each data member should also be defined in this class.

Note: While getting the value for social group, restrict the user to only enter ‘f’ or ‘F’ for female, ‘m’ or’ M’ for male and ‘k’ or ‘K’ for kids.

3) Create another class named Mov_Que (List class); to create a queue for each movie, this class should define three variables, Front pointer, Rear pointer and counter. The class should also define the following functions:
a) Constructor(): Default constructor of the class.
b) Destructor(): Destructor to destroy the memory gained by the use of new operator.
c) add_Ticket(): This method should enter the new ticket purchased at the rear.
d) Total_Visitors(): This method should return the total number of visitors of movie.
e) Total_Revenue(): This method should return the total revenue of the movie.
f) Popularity(): This method should check the popularity of the movie amongst social group, whether the movie is popular among males, females or kids.

4) In main() function of the program, create three objects of the class Mov_Que which will act like three counters at cinema. These objects should be able to perform all the required functionalities mentioned in the question statement.

5) To get the idea about exact output of program, see Demo.wmv file attached with assignment file.

SOLUTION:

 

VU CS508 03 May 2013 Solved Quizzes

Quiz Start Time: 06:46 PM
Time Left 22
sec(s)

Question # 1of 10 ( Start time: 06:46:29 PM) Total Marks: 1

Following are some of the reasons for studying concepts related to different programming languages EXCEPT

Select correct option:

Increased ability to learn new languages

Increased capability to design communication links C
Increased ability to design new languages

Increased capacity to express programming concepts

Quiz Start Time: 06:46 PM
Time Left 76
sec(s)

Question # 2of 10 ( Start time: 06:47:49 PM) Total Marks: 1

_______ was the first object oriented language.

Select correct option:

COBOL
LISP
JAVA
SIMULA C

Quiz Start Time: 06:46 PM
Time Left 36
sec(s)

Question # 3 of 10 ( Start time: 06:48:20 PM ) Total Marks: 1

Readability is increased by adding several different features/ constructs in the language for performing same task.

Select correct option:

True
False               Not Sure

Quiz Start Time: 06:46 PM
Time Left 28
sec(s)

Question # 4 of 10 ( Start time: 06:49:26 PM ) Total Marks: 1

_____ are a type of Aliasing.

Select correct option:

Pointers
Parameters
Arrays 
Linked List

Quiz Start Time: 06:46 PM
Time Left 74
sec(s)

Question # 5 of 10 ( Start time: 06:50:47 PM ) Total Marks: 1

Programming Language is basically a tool for instructing a computer to perform specified set of task.

Select correct option:

True 
False

Quiz Start Time: 06:46 PM
Time Left 43
sec(s)

Question # 6of 10 ( Start time: 06:51:14 PM) Total Marks: 1

Following are imperative languages EXCEPT

Select correct option:

LISP 
C
FORTRAN
PASCAL

Quiz Start Time: 06:46 PM
Time Left 77
sec(s)

Question # 7of 10 ( Start time: 06:52:10 PM) Total Marks: 1

The declarative language among the following is

Select correct option:

C
PROLOG 
PASCAL
C++

Quiz Start Time: 06:46 PM
Time Left 11
sec(s)

Question # 8of 10 ( Start time: 06:52:34 PM) Total Marks: 1

Following factors influences a portable language design EXCEPT

Select correct option:

Computer architecture
Readability
Programmer’s time
Windows XP

Quiz Start Time: 06:46 PM
Time Left 23
sec(s)

Question # 9 of 10 ( Start time: 06:53:57 PM ) Total Marks: 1

Too much Orthogonality reduces Readability.

Select correct option:

True
False

Quiz Start Time: 06:46 PM
Time Left 15
sec(s)

Question # 10 of 10 ( Start time: 06:55:08 PM ) Total Marks: 1

The variable name have profound effect on _______________.

Select correct option:

Readability
Writability
Orthogonality                       Not Sure
Portability

Quiz Start Time: 06:58 PM
Time Left 68
sec(s)

Question # 1of 10 ( Start time: 06:58:08 PM) Total Marks: 1

First electronic computer was _________

Select correct option:

ENIAC 
Baggage Analytical Engine
Intel 386
IBM x86

Quiz Start Time: 06:58 PM
Time Left 27
sec(s)

Question # 4of 10 ( Start time: 06:58:57 PM) Total Marks: 1

Which of the following is an incorrect option from the following statements regarding ‘objectives of learning new languages ’?

Select correct option:

Help to compare different languages.
Help in transition from one language to other language.
Help in understanding the language piracy policy. 
Help to choose a language for development of a certain application.

Quiz Start Time: 06:58 PM
Time Left 6
sec(s)

Question # 5of 10 ( Start time: 07:00:10 PM) Total Marks: 1

SNOBOL was designed for ___________ purpose.

Select correct option:

String manipulation
AI
Business
Scientific

Quiz Start Time: 06:58 PM
Time Left 53
sec(s)

Question # 6 of 10 ( Start time: 07:01:37 PM ) Total Marks: 1

First language that provided the concept of Pointer data type was _______.

Select correct option:

COBOL
LISP
PL/1 
JAVA

Quiz Start Time: 06:58 PM
Time Left 50
sec(s)

Question # 7of 10 ( Start time: 07:02:23 PM) Total Marks: 1

PROLOG represent _______________ paradigm.

Select correct option:

Declarative 
Formal
Functional
Algorithmic

Quiz Start Time: 06:58 PM
Time Left 32
sec(s)

Question # 8of 10 ( Start time: 07:03:14 PM) Total Marks: 1

COBOL is mainly designed for _______.

Select correct option:

Scientific experiments
Business application 
AI applications
Publishing and writing algorithm

Quiz Start Time: 06:58 PM
Time Left 17
sec(s)

Question # 10of 10 ( Start time: 07:04:28 PM) Total Marks: 1

If a language provides a feature of referencing a variable in more than one way then we say that the language provides _________.

Select correct option:

Aliasing 
Data Mining
Orthogonality
Reliability