Sponsored Links


Results 1 to 2 of 2

Thread: CS301‐ Data Structures Assignment No. 1 Solution Semester Spring 2013

  1. #1
    Administrator Vuhelper's Avatar
    Join Date
    Apr 2011
    Posts
    9,578

    18 CS301‐ Data Structures Assignment No. 1 Solution Semester Spring 2013

    Sponsored Links1



    CS301‐ Data Structures Assignment No.1 Solution Semester Spring 2013 Due Date:22/04/2013

    Assignment No.01

    SEMESTER Spring 2013
    CS301‐ Data Structures
    Total Marks:20
    Due Date:22/04/2013
    Instructions
    Please read the following instructions carefully before solving & submitting assignment: It should
    be clear that your assignment will not get any credit (zero marks) if The assignment is submitted after due date.o The submitted code does NOT compile.o
    The submitted assignment is other than.CPP file.The submitted assignment does NOT open or
    file is corrupted.

    o
    The

    assignment

    is

    copied

    (from

    other

    student

    or

    ditto

    copy

    from

    handouts

    or

    internet).

    Uploading

    instructions

    For

    clarity

    and

    simplicity,

    You

    are

    required

    to

    Upload/Submit

    only

    ONE

    .CPP

    file.

    Don’t

    wait

    for

    grace

    day.

    Grace

    day

    is

    only

    given

    if

    there

    is

    problem

    on

    due

    date.

    Submit

    your

    solution

    within

    due

    date.

    Note

    that

    no

    assignment

    will

    be

    accepted

    through

    email

    if

    there

    is

    any

    problem

    on

    grace

    day


    Note:

    Use

    ONLY

    Dev

    C++

    IDE.

    Objective

    The

    objective

    of

    this

    assignment

    is


    o
    To

    make

    you

    familiar

    with

    linked

    list

    data

    structure

    and

    programming

    techniques

    to

    implement

    linked

    list.



    For

    any

    query

    about

    the

    assignment,

    contact

    at

    cs301@vu.edu.pk

    GOOD

    LUCK


    Marks: 20
    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 valu
    e. There can be more than one value in one node but
    pointer will remain one.
    Write a C++ program to implement linked list data structur
    e. 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 nu
    mber of nodes in the list.
    After this give the name to node and save 6 different va
    lues 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 sma
    llest 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 duplic
    ate 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.

    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 exac
    t output of program, see Demo.wmv file
    attached with assignment file.

    Lectures

    Covered:

    This

    assignment

    covers

    Lecture

    #

    1

    5

    Deadline:

    Your

    assignment

    must

    be

    uploaded

    /

    submitted

    on

    /

    before,

    April

    22,

    2013.

    headNode
    currentNode
    lastCurrentNode
    size = 5
    9
    8
    7
    6
    5
    4
    9
    8
    7
    6
    5
    3
    9
    8
    7
    6
    5
    2
    9
    8
    7
    6
    5
    9
    2
    7
    6
    1
    5
    1
    XYZ
    ABC
    QRS
    X12
    DCB
    Name of
    Node
    DCB
    X12
    QRS
    ABC
    XYZ
    The list is shown (in ascending order) on the basis of sum of all values in node.

    Sponsored Links

    Assignment1_CS301.pdf

  2. #2
    Administrator Vuhelper's Avatar
    Join Date
    Apr 2011
    Posts
    9,578
    Idea Solution

    #include<iostream.h>
    #include<cstdlib>
    #include<conio.h>

    using namespace std;

    struct node
    {

    string data;
    int Age;
    struct node *next;
    };

    class queue
    {



    public:
    node *rear;
    node *frnt;

    queue()
    {
    frnt=rear=NULL;
    }
    void insert();
    void del();
    void show();
    void display();
    void length();

    };


    void queue::insert()
    {

    string namec;
    int agec;

    node *temp = new node;
    cout"\nHow many node you want to create? : ";
    cin>>namec;
    cout"\nEEnter the name of node : ";
    cin>>agec;

    temp->data = namec;
    temp->Age=agec;
    temp->next = NULL;
    if(frnt == NULL){
    frnt = temp;
    }else{
    rear->next = temp;
    }
    rear = temp;

    }


    void queue::show()
    {
    node *ptr1=frnt;
    if(frnt==NULL)
    {
    cout"The Queue is empty!!\n";
    return;
    }
    else
    {
    cout"\nCustomer at the front is : "ptr1->data "\n";

    }
    }

    void queue::del()
    {
    if(frnt==NULL)
    {
    cout"\nSorry. Queue is empty";
    return;
    }
    node *temp;
    temp=frnt;
    frnt=frnt->next;
    cout"\nCustomer removed/served successfully : "temp->data ;
    delete temp;

    }


    void queue::length()
    {

    int x;
    x=0;
    node *ptr1=frnt;
    while(ptr1!=NULL)
    {
    ptr1=ptr1->next;
    x++;
    }
    cout"\nTHe customers are : " x ;
    }


    void queue::display()
    {
    node *ptr1=frnt;
    if(frnt==NULL)
    {
    cout"The Queue is empty!!";
    return;
    }
    cout"\nThe Queue is\n";
    cout "Name Age \n";

    while(ptr1!=NULL)
    {
    cout ptr1-> data ptr1->Age "\n" ;
    ptr1=ptr1->next;
    }

    }

    int main()
    {

    queue q;
    char choice;


    while(1)
    {
    cout "\n1- for Enter/adding nodes in Queue";
    cout "\n2- for Remove/serve a nodes";
    cout "\n3- for Show nodes at front ";
    cout "\n4- for Display all nodes in queue";
    cout "\n5- for Show size of Queue ";
    cout "\n6- for Exit";
    cout "\n\nEnter your option: ";

    cin>>choice;

    switch(choice)
    {
    case '1':

    char check;

    do
    {
    q.insert();
    cout"\n Do u want to enter another nodes(y/n): ";
    cin>>check;
    }
    while(check=='y' || check=='Y');
    break;
    case '2':
    q.del();
    break;
    case '3':
    q.show();
    break;
    case '4':
    q.display();
    break;
    case '5':
    q.length();
    break;
    case '6':
    exit(0);
    break;

    default:

    cout"\n Sorry characters are no allowed. Please enter only option 1-6!!\n";
    break;
    }}

    return 0;}

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 06-18-2013, 10:46 PM
  2. Assignment No. 4 SEMESTER Spring 2013 CS301- Data Structures
    By Xpert in forum Assignments & Solutions
    Replies: 0
    Last Post: 06-15-2013, 07:03 PM
  3. Replies: 0
    Last Post: 04-27-2013, 10:07 PM
  4. Replies: 0
    Last Post: 04-18-2013, 03:40 PM
  5. Replies: 0
    Last Post: 01-28-2013, 02:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
-: Vuhelp Disclaimer :-
None of the files shown here are hosted or transmitted by this server. The links are provided solely by this site's users. The administrator's or staff of Vuhelp.net cannot be held responsible for what its users post, or any other actions of its users. You may not use this site to distribute or download any material when you do not have the legal rights to do so. It is your own responsibility to adhere to these terms. If you have any doubts about legality of content or you have any suspicions, feel free to contact us.
Online Education | JhelumSoft