Skip to content

CS301 – Data Structures

3 Topics 35 Posts
  • 0 Votes
    2 Posts
    1k Views
    zareenZ
    Sample Output A1 Sample Output.mp4
  • CS301 Assignment 1 Solution and Discussion

    Solved cs301 assignment 1 solution discussion spring 2020
    4
    0 Votes
    4 Posts
    2k Views
    zareenZ
    @zareen 100% Solution Code #include <iostream> using namespace std; /* The Student class */ class Student { private: string firstname, lastname, VUID; int marks; Student *nextStudent; public: // constructor of Student class to initialize data members of class Student(){ VUID = ""; marks = 0; firstname = ""; lastname = ""; nextStudent = NULL; } // Student class method to set VU ID of Student void setVUID(string val){ VUID = val; }; //Student class method to get VU ID of Student string getVUID(){ return VUID; }; // Student class method to set first name of Student void setFirstName(string val){ firstname = val; }; //Student class method to get first name of Student string getFirstName(){ return firstname; }; // Student class method to set last name of Student void setLastName(string val){ lastname = val; }; //Student class method to get last name of Student string getLastName(){ return lastname; }; //Student class method to set the Marks of Student void setMarks(int val) { marks = val; }; // Student class method to get the Marks of Student int getMarks() { return marks; } //Student class method to point current Student to next Student void setNext(Student *nextStudent) { this->nextStudent = nextStudent; } // Student class method to get memory address where pointer is pointing Student *getNext() { return nextStudent; } }; /* The List class */ class List { private: Student * head; Student * current; public: // constructor of list class to initialize data members of class List() { head = new Student(); head->setNext(NULL); current = NULL; } // list class method to add Students into list void add() { Student *newStudent = new Student(); int loc_marks = 0; string loc_vuid = "", loc_fname = "", loc_lname = ""; cout<<"\nEnter VU ID: "; cin>>loc_vuid; newStudent->setVUID(loc_vuid); cout<<"Enter Marks: "; cin>>loc_marks; newStudent->setMarks(loc_marks); cout<<"Enter First Name: "; cin>>loc_fname; newStudent->setFirstName(loc_fname); cout<<"Enter Last Name: "; cin>>loc_lname; newStudent->setLastName(loc_lname); if(head->getNext() == NULL){ newStudent->setNext(NULL); head->setNext(newStudent); current = newStudent; } else{ Student *temp = head; while(temp->getNext() != NULL && temp->getNext()->getMarks() >= loc_marks){ temp = temp->getNext(); } current = temp; newStudent->setNext(current->getNext()); current->setNext( newStudent ); current = newStudent; } }; // list class method to get the information of Student void getInfo() { if (current != NULL){ cout<<"VU ID: "<<current->getVUID()<<endl; cout<<"Marks: "<<current->getMarks()<<endl; cout<<"First Name: "<<current->getFirstName()<<endl; cout<<"Last Name: "<<current->getLastName()<<endl<<endl; } }; // list class method to move current to next Student bool next() { if (current == NULL){ return false; } current = current->getNext(); }; // frient function to list class to show all students in the list friend void showStudents(List list){ Student* savedCurrent = list.current; list.current = list.head; for(int i = 1; list.next(); i++){ list.getInfo(); } list.current = savedCurrent; }; }; main() { int input = 0; List lst; while(input != -1) { cout<<"1. To Add New Student in Ranking"<<endl; cout<<"2. To Display Ranking"<<endl; cout<<"3. To Close"<<endl<<endl; cout<<"Enter Your Choice: (1, 2 or 3) "; cin>> input; if(input == 1) { lst.add(); cout<<"Student's information saved successfully.\n"; } else if(input == 2) { cout<<"\nRanking Chart"<<endl; showStudents(lst); return 0; } else { return 0; } } }
  • CS301 Assignment 1 Solution and Discussion

    Solved cs301 assignment 1 solution discussion fall 2019
    3
    0 Votes
    3 Posts
    1k Views
    zareenZ
    .CPP File Code using namespace std; #include <stdlib.h> #include <iostream> struct StudentDetail{ string name; string vuid; }; //class Node* head; class Node{ struct StudentDetail newStd; class Node* next; class Node* prev; void Set(string name,string vuid) { newStd.name=name; newStd.vuid=vuid; } Node Get() { } void setNext(string name,string vuid){ if(next==NULL) { } else { class Node* newNode= new Node(); newStd.name=name; newStd.vuid=vuid; newNode->next= newNode; } } string getNext() { next; } void setPrev(string name,string vuid){ if(next==NULL) { } else { class Node* newNode= new Node(); newStd.name=name; newStd.vuid=vuid; newNode->next= newNode; } } string getPrev() { prev; } }; class DoublyLinkedList{ public: struct StudentDetail newStd; class DoublyLinkedList* headPtr; class DoublyLinkedList* curPtr; class DoublyLinkedList* nextPtr; int size; //dfdf class DoublyLinkedList* headDlinkList=NULL; void addAtBegining(string vuid, string name) { class DoublyLinkedList* dNode= new DoublyLinkedList(); dNode->newStd.vuid=vuid; dNode->newStd.name=name; dNode->nextPtr=headDlinkList; headDlinkList= dNode; dNode->curPtr=dNode; } void addAtEnd(string vuid, string name) { class DoublyLinkedList* dNode= new DoublyLinkedList(); dNode->newStd.vuid=vuid; dNode->newStd.name=name; dNode->nextPtr=headDlinkList; headDlinkList= dNode; dNode->curPtr=dNode; } void delNode() { class DoublyLinkedList* temp1=curPtr; class DoublyLinkedList* temp2= temp1; temp1->nextPtr= temp2->nextPtr; free(temp2); } void print() { class DoublyLinkedList* temp= headDlinkList; while(temp!=NULL) { cout<<temp->newStd.vuid<<" "<<temp->newStd.name<<endl; temp= temp->nextPtr; } } }; int main() { string vuid,name; cout<<"Add your vuID and Name at First Position "<<endl; cout<<"_ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ __ _ _"<<endl; DoublyLinkedList dlist1; cin>>vuid; cin>>name; dlist1.addAtBegining(vuid,name); dlist1.print(); cout<<"Insertion At Beginning in doubly Link List "<<endl; cout<<"_ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ __ _ _"<<endl; cin>>vuid; cin>>name; dlist1.addAtBegining(vuid,name); dlist1.print(); cout<<"Insertion At End in doubly Link List "<<endl; cout<<"_ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ __ _ _"<<endl; cin>>vuid; cin>>name; dlist1.addAtEnd(vuid,name); dlist1.print(); cout<<"Deletion of Current Node (Last Node) "<<endl; cout<<"_ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ __ _ _"<<endl; dlist1.delNode(); dlist1.print(); } Download .cpp File https://youtu.be/lG5dpgvNi1s
How to Build a $1,000/Month PAK VS BAN Live Live Cricket Streaming
File Sharing

0

Online

3.0k

Users

2.8k

Topics

8.2k

Posts
| |