Lab Manual 03 DS
Lab Manual 03 DS
Lab Manual
Submitted by: Abdullah
Section: Blue
class Calculator{
public:
if(fib<=1){
return fib;
}
else{
return Fibonacci(fib-1)+Fibonacci(fib-2);
}
}
};
cout<<"5. Exit"<<endl;
cout<<"Enter your choice"<<endl;
cin>>ch;
switch(ch){
case 1:
int ss;
cout<<"Enter Value to which you want to sum"<<endl;
cin>>ss;
int su;
su=c1.sum(ss);
cout<<"Sum is: "<<su<<endl;
break;
case 2:
int ff;
cout<<"Enter Value of which you want to find factorial"<<endl;
cin>>ff;
long long f;
f=c1.fac(ff);
cout<<"factorial is: "<<f<<endl;
break;
case 3:
cout<<"Enter the number of terms for fibonacci sequence"<<endl;
int terms;
cin>>terms;
if(terms<=0){
cout<<"Enter the positive number"<<endl;
}
5|Page
else{
for(int i=0;i<terms;i++){
cout<<c1.Fibonacci(i)<<" ";
}
}
break;
case 4:
int val,pow;
cout<<"Enter the number "<<endl;
cin>>val;
cout<<"Enter the power "<<endl;
cin>>pow;
int powe;
powe=c1.Power(val,pow);
cout<<"Power is "<<powe<<endl;
break;
case 5:
return 0;
break;
default:
cout<<"Invalid input....."<<endl;
}
}
return 0;
}
6|Page
Output:
7|Page
Program:
#include <iostream>
using namespace std;
struct Node{
string title;
Node *Next;
};
class SongPlaylist{
public:
Node *Head;
Node *Tail;
public:
SongPlaylist(){
Head=NULL;
Tail=NULL;
}
void insert(){
Node *temp= new Node;
cout<<"Enter the song name: ";
cin>>temp->title;
temp->Next=NULL;
if(Head==NULL){
Head=temp;
Tail=temp;
}
else{
Tail->Next=temp;
8|Page
Tail=temp;
}
}
}
else{
cout<<temp->title<<" "<<endl;
Forward_Display(temp->Next);
}
}
}
else{
Reverse_Display(temp->Next);
cout<<temp->title<<" "<<endl;
}
}
};
cout<<"4.Exit"<<endl;
cout<<"Enter your choice"<<endl;
cin>>ch;
switch(ch){
case 1:
l1.insert();
break;
case 2:
l1.Forward_Display(l1.Head);
break;
case 3:
l1.Reverse_Display(l1.Head);
break;
case 4:
return 0 ;
break;
default:
cout<<"Invalid input..."<<endl;
}
return 0;
}
10 | P a g e
Output: