Skip to content

Commit 01ef88d

Browse files
committed
initial commit
1 parent 724c83f commit 01ef88d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+442
-0
lines changed

Lab_1/Q1/Minimum_Element_in_Array.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <stdio.h>
2+
3+
int main(){
4+
int arr[5];
5+
for(int i=0;i<5;i++){
6+
printf("enter element %d: ",i+1);
7+
scanf("%d",&arr[i]);
8+
}
9+
int small=arr[0];
10+
int pos=0;
11+
for(int i=0;i<5;i++)
12+
{
13+
if(arr[i]<small){
14+
small=arr[i];
15+
pos=i+1;
16+
}
17+
}
18+
printf("will be %d at position %d",small,pos);
19+
return 0;
20+
}

Lab_1/Q1/Minimum_Element_in_Array.exe

53 KB
Binary file not shown.

Lab_1/Q1/Output.PNG

17.2 KB
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include<iostream>
2+
3+
using namespace std;
4+
5+
int main(){
6+
int number[4],largest,pos=0;
7+
for(int i=0;i<4;i++){
8+
cout<<"enter element "<<i+1<<": ";
9+
cin>>number[i];
10+
pos=i;
11+
}
12+
number[0]>number[1] && number[0]>number[2]?largest=number[0]:number[1]>number[2]?largest=number[1]:largest=number[2];
13+
cout<<"largest number is "<<largest<<" at position "<<pos;
14+
}
Binary file not shown.

Lab_1/Q2/Output.PNG

21.5 KB

Lab_1/Q3/NumberPattern.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <stdio.h>
2+
int main()
3+
{
4+
int a, i, j;
5+
for(a = 1;a <= 3;a++)
6+
{
7+
for(i = 3;i > a;i--)
8+
{
9+
printf(" ");
10+
}
11+
for(j = 1;j <= a;j++)
12+
{
13+
printf("%d", j);
14+
}
15+
printf("\n");
16+
}
17+
}

Lab_1/Q3/NumberPattern.exe

52.9 KB
Binary file not shown.

Lab_1/Q3/Output.PNG

13.4 KB

Lab_1/Q4/Output.PNG

10.9 KB

Lab_1/Q4/Table_of_a_Number.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include<iostream>
2+
3+
using namespace std;
4+
5+
int main(){
6+
int opp;
7+
cout<<"\n1.Press 1 to print table of entered number";
8+
cout<<"\n2.press 2 to exit";
9+
cout<<"\nenter your choice: ";
10+
cin>>opp;
11+
switch (opp)
12+
{
13+
case 1:
14+
int number;
15+
cout<<"\nenter number to display its table: ";
16+
cin>>number;
17+
for(int i=1;i<=10;i++)
18+
cout<<number<<"x"<<i<<"="<<i*number<<"\n";
19+
break;
20+
case 2:
21+
exit(0);
22+
break;
23+
default:
24+
cout<<"wrong choice!";
25+
break;
26+
}
27+
}

Lab_1/Q4/Table_of_a_Number.exe

56.1 KB
Binary file not shown.

Lab_1/Q5/InsertionSort.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <math.h>
2+
#include <stdio.h>
3+
4+
void insertionSort(int arr[], int n){
5+
int i, key, j;
6+
for (i = 1; i < n; i++){
7+
key = arr[i];
8+
j = i - 1;
9+
while (j >= 0 && arr[j] > key){
10+
arr[j + 1] = arr[j];
11+
j = j - 1;
12+
}
13+
arr[j + 1] = key;
14+
}
15+
}
16+
17+
void printArray(int arr[], int n){
18+
int i;
19+
for (i = 0; i < n; i++)
20+
printf("%d ", arr[i]);
21+
printf("\n");
22+
}
23+
24+
int main(){
25+
int n;
26+
printf("enter size of array: ");
27+
scanf("%d",&n);
28+
int arr[n];
29+
for(int i=0;i<n;i++){
30+
printf("enter element %d: ",i+1);
31+
scanf("%d",&arr[i]);
32+
}
33+
insertionSort(arr, n);
34+
printArray(arr, n);
35+
return 0;
36+
}
37+

Lab_1/Q5/InsertionSort.exe

118 KB
Binary file not shown.

Lab_1/Q5/Output.PNG

13.2 KB

Lab_2/Q1/CopyString.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include<iostream>
2+
#include<string.h>
3+
4+
using namespace std;
5+
6+
int main(){
7+
char string[10],string1[10];
8+
cout<<"enter any string: ";
9+
gets(string);
10+
int len=strlen(string);
11+
for(int i=0;i<len;i++){
12+
string1[i]=string[i];
13+
}
14+
cout<<"the copied string is " << string1;
15+
return 0;
16+
}

Lab_2/Q1/CopyString.exe

55.1 KB
Binary file not shown.

Lab_2/Q1/Output.PNG

10.6 KB

Lab_2/Q2/CountWords_in_String.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include<iostream>
2+
#include<string.h>
3+
4+
using namespace std;
5+
6+
int main(){
7+
char str[100];
8+
cout<<"enter any sentence: ";
9+
gets(str);
10+
int len=strlen(str),count=1;
11+
for(int i=0;i<len;i++){
12+
if(str[i]==' '){
13+
count++;
14+
}
15+
}
16+
cout<<"there are "<< count<<" words in the string";
17+
}

Lab_2/Q2/CountWords_in_String.exe

55.3 KB
Binary file not shown.

Lab_2/Q2/Output.PNG

11.5 KB

Lab_2/Q3/Output.PNG

10.8 KB

Lab_2/Q3/Reverse_a_String.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include<iostream>
2+
#include<string.h>
3+
4+
using namespace std;
5+
6+
int main(){
7+
char str[50],temp;
8+
cout<<"enter any string: ";
9+
gets(str);
10+
int len=strlen(str)-1;
11+
for(int i=0; i<len;i++,len--){
12+
temp=str[i];
13+
str[i]=str[len];
14+
str[len]=temp;
15+
}
16+
cout<<"Reversed string is: "<<str;
17+
}

Lab_2/Q3/Reverse_a_String.exe

55.1 KB
Binary file not shown.

Lab_2/Q4/DeleteVowel_from_String.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <Iostream>
2+
#include<string.h>
3+
4+
using namespace std;
5+
6+
int check_vowel(char str);
7+
int main()
8+
{
9+
char str[100],new_str[100];
10+
cout<<"enter a string: ";
11+
gets(str);
12+
int count=0;
13+
for(int i=0;str[i]!='\0';i++)
14+
{
15+
if(check_vowel(str[i]) == 0)
16+
{
17+
new_str[count] = str[i];
18+
count++;
19+
}
20+
}
21+
cout<<new_str;
22+
return 0;
23+
}
24+
int check_vowel(char ch)
25+
{
26+
char vow[10]={'a','e','i','o','u','A','E','I','O','U'};
27+
int flag=0;
28+
for(int j=0;j<strlen(vow);j++){
29+
if(ch==vow[j]){
30+
flag=1;
31+
}
32+
}
33+
if(flag==1)
34+
return 1;
35+
else
36+
return 0;
37+
}

Lab_2/Q4/DeleteVowel_from_String.exe

55.7 KB
Binary file not shown.

Lab_2/Q4/Output.PNG

17.3 KB

Lab_3/Q1/Addition_with_Class.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include<iostream>
2+
3+
using namespace std;
4+
5+
class Addition{
6+
private:
7+
int var1;
8+
int var2;
9+
int sum;
10+
public:
11+
int displaysum(){
12+
return sum;
13+
}
14+
Addition(){
15+
cout<<"enter 1st variable: ";
16+
cin>>var1;
17+
cout<<"enter 2nd variable: ";
18+
cin>>var2;
19+
sum=var1+var2;
20+
}
21+
};
22+
23+
int main(){
24+
Addition obj;
25+
cout<<"sum is: "<<obj.displaysum();
26+
}

Lab_3/Q1/Addition_with_Class.exe

56.5 KB
Binary file not shown.

Lab_3/Q1/Output.PNG

15.8 KB
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include<iostream>
2+
3+
using namespace std;
4+
5+
class Prime{
6+
private:
7+
int number;
8+
bool is_prime;
9+
10+
void prime_no(){
11+
for(int i=2;i<=number/2;i++){
12+
if(number%i==0){
13+
is_prime=false;
14+
break;
15+
}
16+
}
17+
is_prime?cout<<number<<" is a prime number":cout<<number<<" is not a prime number";
18+
}
19+
public:
20+
Prime(){
21+
is_prime=true;
22+
cout<<"enter number:";
23+
cin>>number;
24+
prime_no();
25+
}
26+
};
27+
28+
int main(){
29+
Prime obj;
30+
}
56.5 KB
Binary file not shown.

Lab_3/Q2/Output.PNG

16.5 KB

Lab_3/Q3/Output.PNG

19.4 KB

Lab_3/Q3/Student_Record_Class.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include<iostream>
2+
#include<string.h>
3+
4+
using namespace std;
5+
6+
class Student{
7+
private:
8+
int age;
9+
int roll_no;
10+
char section;
11+
string name;
12+
string crs;
13+
public:
14+
Student(){
15+
cout<<"your name: ";
16+
getline(cin,name);
17+
cout<<"your course: ";
18+
getline(cin,crs);
19+
cout<<"your age: ";
20+
cin>>age;
21+
cout<<"your section: ";
22+
cin>>section;
23+
cout<<"your roll number: ";
24+
cin>>roll_no;
25+
}
26+
void getdata(){
27+
cout<<"name of the student is "<<name;
28+
cout<<", "<<name<<" is "<<age<<" years old";
29+
cout<<", "<<name<<" is doing "<<crs<<" section is "<<section<<" and roll number is "<< roll_no;
30+
}
31+
};
32+
33+
int main(){
34+
Student obj;
35+
obj.getdata();
36+
}

Lab_3/Q3/Student_Record_Class.exe

59.9 KB
Binary file not shown.
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 rectangle{
4+
private:
5+
float length;
6+
float breath;
7+
float area;
8+
void calc(){
9+
this->area=length*breath;
10+
}
11+
public:
12+
rectangle(float l, float b){
13+
this->length=l;
14+
this->breath=b;
15+
calc();
16+
}
17+
void compare(rectangle object){
18+
this->area > object.area ? cout<<"area of rectangle 1 is: "<<
19+
this->area <<" which is bigger than rectangle 2" : this->area < object.area?cout<<"area of rectangle 2 is: "
20+
<<object.area<<" which is bigger than rectangle 1":cout<<"they both are equal";
21+
}
22+
};
23+
int main(){
24+
float len[2],brt[2];
25+
for(int i=0;i<2;i++){
26+
cout<<"enter length of rectangle "<<i+1<<": ";
27+
cin>>len[i];
28+
cout<<"enter breath of rectangle "<<i+1<<": ";
29+
cin>>brt[i];
30+
}
31+
rectangle obj1(len[0],brt[0]),obj2(len[1],brt[1]);
32+
obj1.compare(obj2);
33+
}
Binary file not shown.

Lab_4/Q1/Output.PNG

20.8 KB
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include<iostream>
2+
#include<string.h>
3+
4+
using namespace std;
5+
6+
class privatemem{
7+
private:
8+
string data;
9+
int i;
10+
public:
11+
privatemem(){
12+
this->data="this is a secret mesage";
13+
i=5;
14+
}
15+
};
16+
int main(){
17+
privatemem obj;
18+
string *ptr = (string *)&obj;
19+
cout<<*ptr;
20+
}
57.8 KB
Binary file not shown.

Lab_4/Q2/Output.PNG

11.7 KB

Lab_4/Q3/Static_Variable.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include<iostream>
2+
3+
using namespace std;
4+
5+
class statics{
6+
static int i;
7+
statics(){
8+
i++;
9+
}
10+
};
11+
12+
int statics :: i = 0;
13+
14+
int main(){
15+
statics obj();
16+
}

0 commit comments

Comments
 (0)