Latest Activity In Study Groups

Join Your Study Groups

VU Past Papers, MCQs and More

We non-commercial site working hard since 2009 to facilitate learning Read More. We can't keep up without your support. Donate.

CS301 Data Structures Assignment No.01 Fall 2021 Solution / Discussion

Views: 916

Replies to This Discussion

Share the Assignment Questions & Discuss Here.... 

Stay touched with this discussion, Solution idea will be uploaded as soon as possible in replies here before the due date.

CS301 Assignment 1 Fall 2021 solution idea:

 

code:

#include <iostream>
#include<conio.h>
using namespace std;
class student
{
public:
string name;
int code;
student *next_add;
};
class linked_list
{
public:
student *head =NULL;
void menu();
int get_code();
string get_name();
string set_name(string n);
void insert();
void show_all();
void show_one();
void show_two();
void show_three();
void show_four();

};
string linked_list :: get_name()
{
string name;
cout"Enter the Name of Student: ";
cout" "endl;
cout"(Enter your student id according to assignment instruction)"endl;
cout""endl;
cin>>name;
cout" "endl;
return name;
}
int linked_list ::get_code()
{
int code;
cout" Course Name Course Code "endl;
cout"Introduction to Computing 1 "endl;
cout"Introduction to Programming 2 "endl;
cout"Data Structures 3 "endl;
cout"Object Oriented Programming 4 "endl;
cout" "endl;
cout"Enter the Course Code: ";
cout" "endl;
cin>>code;
cout" "endl;
return code;


}
string linked_list ::set_name(string n)
{
return n;
}
void linked_list :: insert(){
student *new_node = new student;
new_node -> name = get_name();
new_node ->code = get_code();
new_node -> next_add = NULL;
if(head==NULL)
{
head = new_node;
}
else {
student *ptr = head;
while (ptr ->next_add != NULL)
{
ptr = ptr -> next_add;
}
ptr -> next_add = new_node;
}
cout"Student' s Information Saved Successfully. ";
cout" "endl;
}
void linked_list ::menu()
{
starting:
int choice;
cout"0. Display All Students "endl;
cout"1. Display All Students Enrolled in Introduction to Computing"endl;
cout"2. Display All Students Enrolled in Introduction to Programming"endl;
cout"3. Display All Students Enrolled in Data Structure"endl;
cout"4. Display All Students Enrolled in Object Oriented Programming"endl;
cout"5. Close the Program"endl;
cout" "endl;
cout"Select an Option for Required Operation:"endl;
cin>>choice;
if(choice == 0){
show_all();

}
else if(choice == 1){
show_one();

}
else if(choice == 2){
show_two();

}
else if(choice == 3){
show_three();

}
else if(choice == 4){
show_four();

}
else if(choice == 5){
exit(0);

}
// switch(choice)
// {
// case 0:
// show_all();
// break;
// case 1:
// show_one();
// break;
// case 2:
// show_two();
// break;
// case 3:
// show_three();
// break;
// case 4:
// show_four();
// break;
// case 5:
// exit(0);

// }
goto starting;
}
void linked_list ::show_all()
{
int count =0;
cout" "endl;
cout"\n Following Student are Enrolled in All Courses."endl;
cout" "endl;
student *ptr = head;
while (ptr != NULL)
{
cout"\n Student Name: "set_name(ptr ->name);
count++;
ptr = ptr -> next_add;
}
cout"\n Enrollment Count: "count;
cout" "endl;
}
void linked_list :: show_one()
{
int count =0;
cout"\n Following Student are Enrolled in Introduction to Computing."endl;
student *ptr = head;
while (ptr != NULL)
{
if(ptr -> code == 1){
cout"\n Student Name: "set_name(ptr ->name);
count++;
}
ptr = ptr -> next_add;
}
cout"\n Enrollment Count: "count;
cout" "endl;
cout" "endl;
}
void linked_list :: show_two()
{
int count =0;
cout"\n Following Student are Enrolled in Introduction to Programming."endl;
student *ptr = head;
while (ptr != NULL)
{
if(ptr -> code == 2){
cout"\n Student Name: "set_name(ptr ->name);
count++;
}
ptr = ptr -> next_add;
}
cout"\n Enrollment Count: "count;
cout" "endl;
}
void linked_list :: show_three()
{
int count =0;
cout"\n Following Student are Enrolled in Data Structure."endl;
student *ptr = head;
while (ptr != NULL)
{
if(ptr -> code == 3){
cout"\n Student Name: "set_name(ptr ->name);
count++;
}
ptr = ptr -> next_add;
}

cout"\n Enrollment Count: "count;
cout" "endl;
}

void linked_list :: show_four()
{
int count =0;
cout" "endl;
cout"\n Following Student are Enrolled in Object Oriented Programming."endl;
student *ptr = head;
while (ptr != NULL)
{
if(ptr -> code == 4){
cout"\n Student Name: "set_name(ptr ->name);
count++;
}
ptr = ptr -> next_add;
}
cout" "endl;
cout"\n Enrollment Count: "count;
cout" "endl;
}

int main(){
linked_list obj;
char input;
do{
obj.insert();
cout"\n Do you want to add another student? ";
cin>>input;
}while(input=='Y' || input == 'y');
obj.menu();
return 0;
}

CS301 Solution assignment#01 Fall 2021 file link

CS301-Assignment-1-Solution-Fall-2021-By-VU-Ning.pdf

No photo description available.

CS301 Data Structures Assignment No.01 Fall 2021 Solution 

#CS301
#code :
#include<iostream>
using namespace std;
int size=0;
class Student{
public:
string name;
int marks;
Student *nextStudent;
void setName(string setn){
name=setn;
}
string getName(){
return name;
}
void setMarks(int setm){
marks=setm;
}
int getMarks(){
return marks;
}
void setNextStudent(Student *setAddress){
nextStudent=setAddress;
}
Student* getNextStudent(){
return nextStudent;
}
};
class Stack{
public:
Student *headStudent=NULL;
bool isEmpty(){
if(headStudent==NULL){
coutendl"Stack is Empty"endl;
return true;
}
else{
return false;
}
}
void push(){
string n;
int m;
Student *newNode=new Student;
cout"Enter the name of Student: "endl;
cin>>n;
newNode->setName(n);
cout"Enter the Marks of Student: "endl;
cin>>m;
newNode->setMarks(m);
newNode->setNextStudent(NULL);
if(headStudent==NULL){
headStudent=newNode;
}
else{
Student *ptr=headStudent;
while ( ptr-> getNextStudent()!=NULL )
{
ptr=ptr->getNextStudent();
}
ptr->setNextStudent(newNode);
}
coutendl"Student Data saved successfully"endl;
size++;
}
void pop(){
if(!isEmpty()){
Student *pre=headStudent;
Student *ptr=headStudent;
while (ptr->getNextStudent()!=NULL)
{
pre=ptr;
ptr=ptr->getNextStudent();
}
if(ptr==headStudent){
headStudent==NULL;
}
else{
pre->setNextStudent(NULL);
}
delete ptr;
size--;
coutendl"Student Data Remove Successfully from database"endl;
}
}
void display(){
if(!isEmpty()){
string n[size];
int m[size],i=0,j=0;
cout"*************************"endl;
cout"The Data of All students: "endl;
cout"Name\t\tMarks"endl;
Student *ptr=headStudent;
while(ptr != NULL)
{
n[i++]=ptr->getName();
m[j++]=ptr->getMarks();
ptr=ptr->getNextStudent();
}
for(int k=size-1;k>=0;k--){
coutn[k]"\t\t"m[k]endl;
}
cout"*************************"endl;
}
}
void shortStack(){
for(int i=0;i<size;i++){
Student *ptr=headStudent;
for(int j=0;j<size-1;j++){
string tmp;
if(ptr->getMarks()<ptr->getNextStudent()->getMarks()){
// ptr->setMarks(ptr->getMarks() + ptr->getNextStudent() );
// some statement Goes here
}
ptr=ptr->getNextStudent();
}
}
}
void top(){
if(!isEmpty()){
// shortStack();
coutendlendl"Top Positions:"endl;
coutendl"Name\t\tMarks";
Student *ptr=headStudent;
for(int k=0;k<3;k++){
coutendlptr->getName()"\t\t"ptr->getMarks();
ptr=ptr->getNextStudent();
}
coutendlendl;
}
}
};
int main()
{
Stack s;
while (true)
{
int choice;
coutendl"*************************************************"endl;
cout"1. To Add a student in the stack"endl;
cout"2. To Remove a student from stack"endl;
cout"3. Display all students of stack"endl;
cout"4. Display top 3 students of stack"endl;
cout"5. Press 5 or any other key to close the program"endl;
cout"*************************************************"endl;
cout"Enter your choice (1, 2, 3, 4, 5):"endl;
cin>>choice;
switch (choice)
{
case 1:
s.push();
break;
case 2:
s.pop();
break;
case 3:
s.display();
break;
case 4:
s.top();
break;
default:
exit(0);
break;
}
}
return 0;
}

Cs301 Assignment no 1 fall 2020

 

#include <iostream>

using namespace std;

//Structure of the Node

class student

{

                public:

int marks;

string name;

 

student *link=NULL;

};

student *top = NULL;

bool isempty()

{

 if(top == NULL)

 return true;

 else

 return false;

}

//Function to insert an element in stack

void push (int marks ,string name)

{

  student *ptr = new student();

  ptr->marks = marks;

  ptr->name = name;

  ptr->link = top;

  top = ptr;

  cout"Student Record SUCCESSFULLY Saved\n\n";

}

//Function to delete an element from the stack

void pop ()

{

 if ( isempty() )

  cout"Stack is Empty\n\n";

 else

 {

  student *ptr = top;

  top = top -> link;

  delete(ptr);

  cout"Student deleted Successfully\n";

 }

}

 

 void reverse()

    {

        student *current = top;

        student *prev = NULL, *link = NULL;

        while (current != NULL)

        {

            // Store next

            link = current->link;

            // Reverse current node's pointer

            current->link = prev;

            // Move pointers one position ahead.

            prev = current;

            current = link;

        }

        link = prev;

        if ( isempty() )

  cout"Stack is Empty\n";

 else

 {

   cout"Name""                                        ""Marks\n""----""                                              ""----\n";

  for (int i; i<=2;i++){

 

  {   coutprev->name"                                            "prev->marks"\n";

   prev=prev->link;

  }

 }

}

    }

// Function to Display the stack

void displayStack()

{

 if (isempty())

  cout"Stack is Empty\n";

 else

 {

  student *temp=top;

  cout"Name""                                         ""Marks\n""----""                                              ""----\n";

  while(temp!=NULL)

  {   couttemp->name"                                          "temp->marks"\n";

   temp=temp->link;

  }

  cout"\n";

 }

 }

 

// Main function

int main()

{

 

int choice, flag=1, value;

 string name;

 

while (choice <5){

                               

cout"1.             To add a student in Stack.\n 2.                   To remove a Student from Stack.\n 3.    Display all students of Stack.\n4.            Display top 3 positions of students. \n5.               Press 5 or any other key to close the program.\n\nEnter your choice (1,2,3,4,5):";

 

 cin>>choice;

 switch (choice)

 {

 case 1:cout"Enter Name of Student:";

         cin>>name;

          cout"Enter Marks of Student:";

         cin>>value;

         push(value,name);

         break;

 case 2: pop();

         break;

 case 3: displayStack();

         break;

 case 4: reverse();

         break;

         flag=0;

 }

}

 

system("PAUSE");

}

 

CS301 Solution fall 2021 file link 

CS301-Assignment-1-Solution-Fall-2021-By-VU-Ning.cpp

CS301 Assignment No 1 + CPP FILE DEC-2021 |100%| |Correct| |Solution| |2021|

#CS301 #CS301Assignment1Fall2021 #CS301Fall2021
CS301 Assignment 1 Solution fall 2021 | CS301 assignment 1 solution 2021 | File in Description

CS301 assignment 1 solution fall 2021 | cs301 assignment solution with source file

#CS301 #CS301Assignment1Fall2021 #CS301Fall2021
CS301 Assignment No 1 Fall 2021 Solution File 100% Correct

#cs301assignment
cs301 assignment 1 solution 2021,cs301 assignment fall 2021,cs301 assignment solution 2021,cs301

Cs301 Assignment no 1 fall 2020

 

#include <iostream>

using namespace std;

//Structure of the Node

class student

{

                public:

int marks;

string name;

 

student *link=NULL;

};

student *top = NULL;

bool isempty()

{

 if(top == NULL)

 return true;

 else

 return false;

}

//Function to insert an element in stack

void push (int marks ,string name)

{

  student *ptr = new student();

  ptr->marks = marks;

  ptr->name = name;

  ptr->link = top;

  top = ptr;

  cout"Student Record SUCCESSFULLY Saved\n\n";

}

//Function to delete an element from the stack

void pop ()

{

 if ( isempty() )

  cout"Stack is Empty\n\n";

 else

 {

  student *ptr = top;

  top = top -> link;

  delete(ptr);

  cout"Student deleted Successfully\n";

 }

}

 

 void reverse()

    {

        student *current = top;

        student *prev = NULL, *link = NULL;

        while (current != NULL)

        {

            // Store next

            link = current->link;

            // Reverse current node's pointer

            current->link = prev;

            // Move pointers one position ahead.

            prev = current;

            current = link;

        }

        link = prev;

        if ( isempty() )

  cout"Stack is Empty\n";

 else

 {

   cout"Name""                                        ""Marks\n""----""                                              ""----\n";

  for (int i; i<=2;i++){

 

  {   coutprev->name"                                            "prev->marks"\n";

   prev=prev->link;

  }

 }

}

    }

// Function to Display the stack

void displayStack()

{

 if (isempty())

  cout"Stack is Empty\n";

 else

 {

  student *temp=top;

  cout"Name""                                         ""Marks\n""----""                                              ""----\n";

  while(temp!=NULL)

  {   couttemp->name"                                          "temp->marks"\n";

   temp=temp->link;

  }

  cout"\n";

 }

 }

 

// Main function

int main()

{

 

int choice, flag=1, value;

 string name;

 

while (choice <5){

                               

cout"1.             To add a student in Stack.\n 2.                   To remove a Student from Stack.\n 3.    Display all students of Stack.\n4.            Display top 3 positions of students. \n5.               Press 5 or any other key to close the program.\n\nEnter your choice (1,2,3,4,5):";

 

 cin>>choice;

 switch (choice)

 {

 case 1:cout"Enter Name of Student:";

         cin>>name;

          cout"Enter Marks of Student:";

         cin>>value;

         push(value,name);

         break;

 case 2: pop();

         break;

 case 3: displayStack();

         break;

 case 4: reverse();

         break;

         flag=0;

 }

}

 

system("PAUSE");

}

 

RSS

© 2022   Created by + M.Tariq Malik.   Powered by

Promote Us  |  Report an Issue  |  Privacy Policy  |  Terms of Service