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.  1
Semester: Spring 2021

#CS301 Assignment 1 Solution 2021 Spring

Instructions:

Please read the following instructions carefully before submitting the assignment solution:

It should be clear that your assignment will not get any credit/marks if:

  • Assignment is submitted after due date.
  • Submitted assignment does not open or file is corrupt.
  • Assignment is copied (From internet/students).

Recommended Tools:

  • Dev C++

Objectives:

To enable students to understand and practice the concepts of:

  • Linked list implementation
  • Efficient memory management
  • Efficient use of pointer

Assignment Submission Instructions:

You have to submit only .zip file which will have code (.cpp) and screenshot image files on the assignments interface from your LMS account.

Assignment submitted in any other format will not be accepted and will be scaled with zero marks. No excuse will be accepted on submitting solution file in any other format.

Problem Statement:

In the lesson videos and handouts you learned to save only one integer element as data in a node. Please note, it is not compulsory to have only one value in a node. There can be more than one and different types of elements as data of a node but pointer will remain one for singly linked list. Write a C++ program to implement linked list data structure. In this problem every node should have two data elements called name and course of a student and a pointer to link the current node to the next node. Your program should prompt the user to enter name and course code of a https://vustd.com/mth603-assignment-1-solution-2021-spring/

Use the following course names and codes while entering the record of a student.


Course Name Course Code
Introduction to Computing 1
Introduction to Programming 2
Data Structures 3
Object Oriented Programming 4
#CS301 Assignment 1 Solution 2021 Spring

After saving the required information of all students, you need to perform following operations operated through menu showing in sample output video.

  • Show the names of students enrolled in a specific or all courses (user will enter a choice of operation).
  • Show the count of students enrolled in a specific or all courses (user will enter a choice of operation).
  • Option to close the program by selection from menu as showing in sample output video.
  • While testing your application and entering the record of first student, use your VU ID for the name of student. Take screenshot of your input which should be showing your VU ID entered as first student name. Zip your code (.cpp) and screenshot image files and submit zip file from your LMS account.

Sample Output:

For sample output watch the video file “A1 Sample Output.mp4” attached with this assignment file.

Lectures Covered: (Lecture # 1- 8) and Due date to submit solution: (Tuesday, May 18, 2021).

Views: 1336

Replies to This Discussion

#CS301 Assg 1 2021
//vu id XXXXXXXXXXXXXXXXXX
#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 set_name();
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 the student: ";
cin>>name;
return name;
}
int linked_list::get_code(){
int code;
cout"\n\n1. introduction to computing: " ;
cout"\n2. introduction to programming ";
cout"\n3. data structures ";
cout"\n4. object oriented programming ";
cout"\nEnter the course name ";
cin>>code;
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" students information saved successfully.";
}
void linked_list::menu(){
p:
int choice;
cout"\n\n0. display all students ";
cout"\n1. display all students enrolled in introduction to computing ";
cout"\n2. display all students enrolled in introduction to programming ";
cout"\n3. display all students enrolled in data structures ";
cout"\n4. display all students enrolled in object oriented programming ";
cout"\n5. close the program ";
cout"\n\n select an option for required operation: ";
cin>>choice;
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 p;
}
void linked_list::show_all(){
int count=0;
cout"\n\nfollowing students are enrolled in all courses: ";
student *ptr=head;
while(ptr!=NULL){
cout"\nStudent name: " set_name(ptr->name);
count ++;
ptr=ptr->next_add;
}
cout"\nenrollemnet count " count ;
}
void linked_list::show_one(){
int count=0;
cout"\n\nfollowing students are enrolled in intoduction to computing: ";
student *ptr=head;
while(ptr!=NULL){
if(ptr->code==1){
cout"\nStudent name: "set_name(ptr->name);
count ++;
}
ptr=ptr->next_add;
}
cout"\nenrollement cout:"count;
}
void linked_list::show_two(){
int count=0;
cout"\n\nfollowing students are enrolled in intoduction to computing: ";
student *ptr=head;
while(ptr!=NULL){
if(ptr->code==2){
cout"\nStudent name: "set_name(ptr->name);
count ++;
}
ptr=ptr->next_add;
}
cout"\nenrollement cout:"count;
}
void linked_list::show_three(){
int count=0;
cout"\n\nfollowing students are enrolled in intoduction to computing: ";
student *ptr=head;
while(ptr!=NULL){
if(ptr->code==3){
cout"\nStudent name: "set_name(ptr->name);
count ++;
}
ptr=ptr->next_add;
}
cout"\nenrollement cout:"count;
}
void linked_list::show_four(){
int count=0;
cout"\n\nfollowing students are enrolled in intoduction to computing: ";
student *ptr=head;
while(ptr!=NULL){
if(ptr->code==4){
cout"\nStudent name: "set_name(ptr->name);
count ++;
}
ptr=ptr->next_add;
}
cout"\nenrollement cout:"count;
}
main(){
linked_list obj;
char x;
do {
obj.insert();
cout"\ndo you want to add another student?" ;
cin>>x;
}
while(x=='Y'||x=='y');
obj.menu();
}

Solution of CS301 Assignment 1 of Spring 2021 of Data Structures

RSS

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

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