Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 68fb0fb

Browse files
Nishkarsh
1 parent 102cc02 commit 68fb0fb

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed

‎Expt_1_1.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include<iostream>
2+
using namespace std;
3+
class lenght1 //unlike main its not allowed to make variable declarations within member functions/
4+
{
5+
float lenght;
6+
float l1;
7+
public:
8+
void setlenght(float l)
9+
{
10+
lenght=l;
11+
}
12+
void convert()
13+
{
14+
if(lenght>12)
15+
{
16+
l1=(int)lenght/12;
17+
lenght=int(lenght)%12; //note that float does not allow mod function to work upon
18+
}
19+
cout<<"Lenght is "<<l1<<" feets and "<<lenght<<" inches"<<endl;
20+
}
21+
};
22+
int main()
23+
{
24+
cout<<"Program to convert Lenght from inches to foot+inches"<<endl;
25+
float l;
26+
cout<<"Enter lenght in inches"<<endl;
27+
cin>>l;
28+
lenght1 obj;
29+
obj.setlenght(l);
30+
obj.convert();
31+
cout<<endl;
32+
return 0;
33+
}

‎Expt_1_2.cpp

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#include<iostream>
2+
using namespace std;
3+
class Queue
4+
{
5+
public: //all public needed to access outside in main
6+
string name;
7+
int roll_number;
8+
double total_marks;
9+
Queue *next;
10+
void show()
11+
{
12+
cout<<endl;
13+
cout<<"Name of the person is "<<name<<endl<<"Roll number of the person is "<<roll_number<<endl<<"Total marks of the person are "<<total_marks<<endl;
14+
}
15+
}*rear,*front,*node,*ptr,*p;
16+
int main()
17+
{
18+
int quit=0;
19+
cout<<"Hello! This is a program to demonstrate Queue implementation using Classes and Objects"<<endl;
20+
node=new Queue;
21+
cout<<"Enter the name of this person"<<endl;
22+
cin>>node->name;
23+
cout<<"Enter the roll number of this person"<<endl;
24+
cin>>node->roll_number;
25+
cout<<"Enter the total marks of this person"<<endl;
26+
cin>>node->total_marks;
27+
node->next=NULL;
28+
front=node;
29+
rear=node;
30+
node->show();
31+
cout<<endl;
32+
cout<<"Let the party begins"<<endl;
33+
do
34+
{
35+
cout<<"\t\t\t\tOption Menu"<<endl;
36+
cout<<"1) Insert"<<endl;
37+
cout<<"2) Delete"<<endl;
38+
cout<<"3) Show"<<endl;
39+
cout<<"4) Exit"<<endl;
40+
int ch;
41+
cout<<"Enter your choice"<<endl;
42+
cin>>ch;
43+
switch(ch)
44+
{
45+
case 1: cout<<"Insertion at end"<<endl;
46+
p=new Queue;
47+
cout<<"Enter the name of this person"<<endl;
48+
cin>>p->name;
49+
cout<<"Enter the roll number of this person"<<endl;
50+
cin>>p->roll_number;
51+
cout<<"Enter the total marks of this person"<<endl;
52+
cin>>p->total_marks;
53+
rear->next=p;
54+
p->next=NULL;
55+
rear=p;
56+
break;
57+
case 2: cout<<"Deletion at beginning"<<endl;
58+
cout<<"Object to be deleted is"<<endl;
59+
front->show();
60+
ptr=front;
61+
front=front->next;
62+
delete ptr;
63+
break;
64+
case 3: cout<<"Traversal"<<endl;
65+
for(ptr=front;ptr!=NULL;ptr=ptr->next)
66+
{
67+
int i=1;
68+
cout<<"The "<<i++<<" Record is of";
69+
ptr->show();
70+
}
71+
break;
72+
case 4: quit=1;
73+
break;
74+
default: cout<<"Wrong Choice! Try again"<<endl;
75+
}
76+
}while(quit!=1);
77+
return 0;
78+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /