DSF Assignment 4

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 22

#include<iostream>

Using namespace std;

#include<string.h>

Class node

Char ID[10];

Char PIN[10];

Public:

Int age;

String name;

String DOB;

Int comments,like;

Bool vi;

Int in;

Void set_ID()

Cout<<”\n\t ENTER ID : “;

Cin>>ID;

Void set_PIN()

Cout<<”\n\t ENTER PASSWORD : “;

Cin>>PIN;

Char* get_ID()

{
Return ID;

Char* get_PIN()

Return PIN;

};

Class friendlist

Public:

Node *frind;

Friendlist *next;

Int dis;

};

Class user_list

Public:

Node *user;

User_list *next;

Friendlist *frind_list;

};
Class queue

Int rare,front;

Node *Q[50];

Public:

Queue(){rare=front=-1; }

Void enque(node *newnode);

Node* deque();

Int empty();

};

Void queue::enque(node *newnode)

If(front==-1&&rare==-1)

Rare=0;

Front=0;

Else if(((rare+1)%50)==front)

Cout<<”\n\t\tQUEUE IS FULL “;

Return ;

}
Q[rare]=newnode;

Rare=(rare+1)%50;

Node* queue::deque()

Node *temp=NULL;

If(rare==front)

Rare=front=-1;

Cout<<”\n\t QUEUE IS EMPTY”;

Else

Temp=Q[front];

Front=(front+1)%50;

//cout<<”\n\t deque “<<temp->name;

Return temp;

Int queue::empty()

If(rare==front)
{

Rare=front=-1;

Return 1;

Else

Return 0;

Class graph

User_list *data;

Public:

Void create();

Void display();

Void make_friend();

Void display_friend();

Void login();

Void display_friend_list(user_list *temp);

Void add_friend(user_list *temp1);

Void display_details(user_list *temp);

Void make_friend2(string a,string b);

Void make_friend3(string a,string b);

Void BFS();

Void PRIMS();

};
Void graph::PRIMS()

Int visit[20],sourse[20],dist[20];

Void graph::BFS()

Queue Q,q;

Int a[100],ab,max=0;

String max_l;

User_list *temp=data;

Node *element,*temp1,VI;

Friendlist *temp3;

Element=temp->user;

Q.enque(element);

q.enque((node*)100);

for(int i=0;i<100;i++)

a[i]=0;

a[element->in]=1;

//cout<<”\n\telement =>”<<element->name;

While(Q.empty()!=1)

Temp1=Q.deque();

//VI=q.deque();

Cout<<”\n\t”<<temp1->name<<” has “<<temp1->comments<<” comments”;

Ab=temp1->comments;
Temp=data;

If(ab>=max)

Max=ab;

Max_l=temp1->name;

While(temp!=NULL)

If(temp->user->name==temp1->name)

//cout<<”\n\t “<<temp->user->name;

Temp3=temp->frind_list;

While(temp3!=NULL)

//cout<<”\n\t 1)”<<temp3->frind->name;

If(a[temp3->frind->in]==0)

A[temp3->frind->in]=1;

//cout<<”\t ans=>”<<temp1->name;

Q.enque(temp3->frind);

q.enque((node*)1);

Temp3=temp3->next;

//cout<<”\n\t “<<temp->user->name;
Temp=temp->next;

Cout<<”\n\t”<<max_l<<” has max “<<max<<” comments”;

Void graph::login()

Int ch=1;

Char ID[20];

Char PIN[10];

User_list *temp=data;

Cout<<”\n\t ENTER USERNAME = “;

Cin>>ID;

Cout<<”\n\t ENTER PASSWORD = “;

Cin>>PIN;

While(temp!=NULL)

If((strcmp(temp->user->get_ID(),ID)==0)&&(strcmp(temp->user-
>get_PIN(),PIN)==0))

Int ch=1;

While(ch)

Cout<<”\n\t *****WELCOME “<<temp->user->name<<” *****”;

Cout<<”\n\t 1.show friend list\n\t 2.make friend\n\t 3.my details\n\t


4.DISPLAY FRIEND\n\t “;

Cout<<”5.QUIT \n\t\tENTER CHOICE == “;

Cin>>ch;
Cout<<”\n\t********************”;

Switch(ch)

Case 1:display_friend_list(temp);

Break;

Case 2:add_friend(temp);

Break;

Case 3:display_details(temp);

Break;

Case 4:display_friend();

Break;

Case 5:ch=0;

Break;

Default:cout<<”\n\t\t WRONG OPSHION “;

Break;

Temp=temp->next;

Void graph::display_details(user_list *temp)

Node *temp_node;

Temp_node=temp->user;
Cout<<”\n\tNAME = “<<temp_node->name;

Cout<<”\n\tAGE =”<<temp_node->age;

Cout<<”\n\tdate of birth = “<<temp_node->DOB;

Void graph::add_friend(user_list *temp1)

Int ch=1,flag=0,nots=0,dis;

User_list *temp2=NULL;

String friend_name;

Friendlist *friend1;

Friendlist *temp_friendlist;

Cout<<”\n\t WHO ARE frinds of “;

Cout<<temp1->user->name;

Ch=1;

While(ch)

Cout<<”\n\t\t ENTER FRIEND NAME == “;

Cin>>friend_name;

Cout<<”\n\tENTER DISTANCE “;

Cin>>dis;

Temp2=data;

While(temp2!=NULL)

If(temp2->user->name==friend_name&&temp2->user->name!=temp1->user-
>name)

Flag=1;

Make_friend3(temp2->user->name,temp1->user->name);
Break;

Else

Temp2=temp2->next;

If(flag==1)

Cout<<”\n\tUSER FOUND “;

Friend1=new friendlist();

Friend1->frind=temp2->user;

Friend1->next=NULL;

If(temp1->frind_list==NULL)

Temp1->frind_list=friend1;

Else

Temp_friendlist=temp1->frind_list;

While(temp_friendlist->next!=NULL)

If(temp_friendlist->frind->name==friend_name)

Nots=100;

Temp_friendlist=temp_friendlist->next;

If(nots!=100)

If(temp_friendlist==NULL)
Temp_friendlist=friend1;

Else

Temp_friendlist->next=friend1;

//cout<<”\n\t”<<temp_friendlist->frind->name;

Else

Cout<<”\n\tUSER NOT FOUND”;

Cout<<”\n\t PRESS 1 TO ADD ANOTHER FRIEND “;

Cout<<”\n\t else PRESS 0 :”;

Flag=0;

Cin>>ch;

Void graph::display_friend_list(user_list *temp)

Int count=0;

Cout<<”\n\t FRIEND LIST => “;

Friendlist *temp_friendlist;

Temp_friendlist=temp->frind_list;

While(temp_friendlist!=NULL)

Cout<<++count<<”)>\t”<<temp_friendlist->frind->name;

Temp_friendlist=temp_friendlist->next;

}
}

Void graph::display_friend()

Int a=0,max=0,count=0,top=0;

User_list *temp;

String name;

Friendlist *temp_friendlist;

Temp=data;

While(temp!=NULL)

Temp_friendlist=temp->frind_list;

//cout<<”\n\tENTRY”;

A=0;

While(temp_friendlist!=NULL)

//cout<<”\n\t”<<temp_friendlist->frind->name;

Temp_friendlist=temp_friendlist->next;

A=a+1;

//cout<<”\n\t”<<count<<”]”<<a<<”\n”;

Cout<<”\n\t “<<temp->user->name<<” has “<<a<<” friends “;

If(a>max)

Max=a;

Top=count;

Name=temp->user->name;

Else

A=0;
Temp=temp->next;

Cout<<”\n\t hightest friend => “<<name;

Void graph::make_friend()

Int ch=1,flag=0;

String name;

User_list *temp1=NULL,*temp2=NULL;

String friend_name;

Friendlist *friend1;

Friendlist *temp_friendlist;

Temp1=data;

While(temp1!=NULL)

Cout<<”\n\tENTER friends of “;

Cout<<temp1->user->name;

Ch=1;

While(ch)

Cout<<”\n\t\tfriends are =>”;

Cin>>friend_name;

Temp2=data;

While(temp2!=NULL)

{
If(temp2->user->name==friend_name&&temp1->user->name!=temp2->user-
>name)

Flag=1;

Make_friend3(temp2->user->name,temp1->user->name);

Break;

Else

Temp2=temp2->next;

If(flag==1)

Cout<<”\n\tUSER FOUND “;

Friend1=new friendlist();

Friend1->frind=temp2->user;

Friend1->next=NULL;

If(temp1->frind_list==NULL)

Temp1->frind_list=friend1;

Else

//cout<<”\n\t list no “<<friend1->frind->name;

Temp_friendlist=temp1->frind_list;

//cout<<”\n\t list no “<<temp_friendlist->frind->name;

While(temp_friendlist->next!=NULL)

Temp_friendlist=temp_friendlist->next;

If(temp_friendlist==NULL)

Temp_friendlist=friend1;

Else
Temp_friendlist->next=friend1;

Cout<<”\n\t”<<temp_friendlist->frind->name;

Else

Cout<<”\n\tUSER NOT FOUND”;

Cout<<”\n\t PRESS 1 TO ADD ANOTHER FRIEND “;

Cout<<”\n\t else PRESS 0 :”;

Flag=0;

Cin>>ch;

Temp1=temp1->next;

Void graph::make_friend3(string a,string b)

Int ch=1,flag=0,nots=0;

String name;

User_list *temp1=NULL,*temp2=NULL;

String friend_name;

Friendlist *friend1;

Friendlist *temp_friendlist;

Temp1=data;

While(temp1!=NULL)

If(temp1->user->name==a)
{

Ch=1;

While(ch)

Friend_name=b;

Temp2=data;

While(temp2!=NULL)

If(temp2->user->name==friend_name&&temp1->user->name!=temp2->user-
>name)

Flag=1;

//make_friend2(temp2->user->name,temp1->user->name);

Break;

Else

Temp2=temp2->next;

If(flag==1)

Cout<<”\n\tUSER FOUND “;

Friend1=new friendlist();

Friend1->frind=temp2->user;

Friend1->next=NULL;

If(temp1->frind_list==NULL)

Temp1->frind_list=friend1;

Else
{

//cout<<”\n\t list no “<<friend1->frind->name;

Temp_friendlist=temp1->frind_list;

//cout<<”\n\t list no “<<temp_friendlist->frind->name;

While(temp_friendlist->next!=NULL)

If(temp_friendlist->frind->name==friend_name)

Nots=100;

Temp_friendlist=temp_friendlist->next;

If(nots!=100)

If(temp_friendlist==NULL)

Temp_friendlist=friend1;

Else

Temp_friendlist->next=friend1;

Cout<<”\n\t”<<temp_friendlist->frind->name;

Else

Cout<<”\n\tUSER NOT FOUND”;

//cout<<”\n\t PRESS 1 TO ADD ANOTHER FRIEND “;

//cout<<”\n\t else PRESS 0 :”;

Flag=0;
Ch=0;

Temp1=temp1->next;

Void graph::create()

Int no_user,count=1;

User_list *head=NULL,*pre=NULL;

Node *temp=NULL;

Cout<<”\n\t ENTER NO OF USER YOU WANT TO ADD => “;

Cin>>no_user;

While(no_user--)

Head=new user_list();

Head->frind_list=NULL;

Head->next=NULL;

Head->user=NULL;

Temp=new node();
Temp->set_ID();

Temp->set_PIN();

Temp->in=count++;

Cout<<”\n\tENTER NAME = “;

Cin>>temp->name;

Cout<<”\n\tENTER DATE OF BIRTH = “;

Cin>>temp->DOB;

Cout<<”\n\tENTER AGE = “;

Cin>>temp->age;

Cout<<”\n\t ENTER LIKES =”;

Cin>>temp->like;

Cout<<”\n\t ENTER COMMENTS = “;

Cin>>temp->comments;

Head->user=temp;

If(pre==NULL)

Data=head;

Else

Pre->next=head;

Pre=head;

Void graph::display()

User_list *temp;

Node *temp_node;

Temp=data;

While(temp!=NULL)

{
Temp_node=temp->user;

Cout<<”\n\tNAME = “<<temp_node->name;

Cout<<”\n\tAGE =”<<temp_node->age;

Cout<<”\n\tdate of birth = “<<temp_node->DOB;

Temp=temp->next;

Int main()

Int ch;

Graph G;

Cout<<”\n\t\t*** WELCOME friendskatta ***\n\n\n”;

Cout<<”\n\t END “;

G.create();

G.make_friend();

G.BFS();

Do

Cout<<”\n\t***** MAIN PAGE *****”;

Cout<<”\n\n\n\n\n\t1.LOGIN PAGE\n\t2.CREATE FRIEND LIST\n\t3.DISPLAY FRIEND LIST


AND\n\tFIND WHO HAS MAX FRIEND\n\t4.display database”;

Cout<<”\n\t5.QUIT\n\t\tENTER CHOICE==”;

Cin>>ch;

Cout<<”\n\t********************”;
Switch(ch)

Case 1:G.login();

Break;

Case 2:G.make_friend();

Break;

Case 3:G.display_friend();

Break;

Case 4:G.display();

Break;

Case 5:ch=0;

Break;

Default:cout<<”\n\t\t wrong option “;

}while(ch);

Return 0;

You might also like