0% found this document useful (0 votes)
51 views16 pages

Name: Neha Amir ID: 160222 Class: BEEE-VI-A Lab No # 01 Task #1

The document contains the code for 11 tasks completed by a student. Each task involves programming concepts like pointers, arrays, strings and functions. The tasks get progressively more complex, starting with basic pointer operations and ending with string manipulation functions.

Uploaded by

Neha Amir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views16 pages

Name: Neha Amir ID: 160222 Class: BEEE-VI-A Lab No # 01 Task #1

The document contains the code for 11 tasks completed by a student. Each task involves programming concepts like pointers, arrays, strings and functions. The tasks get progressively more complex, starting with basic pointer operations and ending with string manipulation functions.

Uploaded by

Neha Amir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Name: Neha Amir

ID: 160222
Class: BEEE-VI-A
LAB NO # 01
TASK #1
#include<iostream>

using namespace std;

int main()

char choice;

do

int a=10;

int b=20;

cout<<a<<endl;

cout<<b<<endl;

cout<<&a<<endl;

cout<<&a<<endl;

int *first_ptr;

first_ptr=&a;
cout<<"value stored in pointer is:"<<*first_ptr<<endl;

first_ptr=&b;

cout<<"value stored in pointer is:"<<*first_ptr<<endl;

int*second_ptr;

second_ptr=first_ptr=&a;

*first_ptr=30;

cout<<a<<endl;

*second_ptr=40;

cout<<a;

cin>>choice;

while(choice=='y'||choice=='Y');

Task# 2
#include <iostream>

using namespace std;

void swap(int *ptr1, int *ptr2);

int main()

char choice;

do
{

int a,b;

cout<<"Enter first variable";

cin>>a;

cout<<"Enter second varialbe";

cin>>b;

cout<<"first variable "<<a<<"\nsecond variable "<<b<<endl;

cout<<"let's SWAP!"<<endl;

swap(&a,&b);

cout<<"first variable = "<<*a<<endl;

cout<<"second variable = "<<b<<endl;

cout<<"press 'y' to restart program";

cin>>choice;

}while(choice=='Y'||choice=='y');

return 0;

void swap(*ptr1, *ptr2)

int c;

c=*ptr1;

*ptr1=*ptr2;
*ptr2=c;

Task #3
#include <iostream>

using namespace std;

void IncrementDecrement(int *num,int operation)

if (operation==1)

int A=*num;

A++;

cout<<"incremented number is "<<A<<endl;

if (operation==2)

int A=*num;

A--;

cout<<"decremented number is "<<A<<endl;

}
int main ()

char choice;

do{

int num;

cout<<"Enter number you want to increment or decrement \n";

cin>>num;

int *ptr=&num;

int operation;

cout<<"Enter operation you want to perform \n 1 for increment \n 2 for


decrement \n";

cin>>operation;

IncrementDecrement(&num,operation);

cout<<"Enter your Choice"<<endl;

cin>>choice;

}while(choice=='Y');

}
Task#4
#include <iostream>

using namespace std;

int Factorial(int *ptr)

int A=*ptr;

int fact=1;

for (int i=A;i>=1;i--)

fact=fact*i;

return fact;

int main ()

char choice;

do{
int num;

cout<<"Enter number you want to find the factorial of ";

cin>>num;

cout<<"The factorial is "<<Factorial(&num)<<endl;

cout<<"Enter your Choice"<<endl;

cin>>choice;

while(choice=='Y');

Task#5
#include <iostream>

using namespace std;

int main ()

char choice;

do

double arr[5]={0,0,0,0,0};
for (int i=0;i<=4;i++)

cout<<"Write marks of student "<<i+1<<endl;

cin>>arr[i];

for (int j=0;j<=4;j++)

cout<<"The marks of student "<<j+1<<" is "<<arr[j]<<endl;

cout<<"Enter your Choice"<<endl;

cin>>choice;

}while(choice=='Y');

Task#6
#include <iostream>

using namespace std;

int main ()

char choice;
do{

int arrA[10]={10,11,12,13,14,15,16,17,18,19};

int arrB[10]={0};

for (int k=0;k<=9;k++)

arrB[k]=arrA[k];

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

cout<<" The element at index "<<i<<" of array A is "<<arrA[i]<<endl;

for (int j=0;j<=9;j++)

cout<<" The element at index "<<j<<" of array B is "<<arrB[j]<<endl;

cout<<"Enter your Choice"<<endl;

cin>>choice;
}while(choice=='Y');

return 0;

Task#7
#include <iostream>

using namespace std;

int main ()

char choice;

do{

int arrA[10]={10,11,12,13,14,15,16,17,18,19};

int arrB[10]={0};

for (int k=0;k<=9;k++)

arrB[k]=arrA[k];

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


{

cout<<" The element at index "<<i<<" of array A is "<<arrA[i]<<endl;

for (int j=0;j<=9;j++)

cout<<" The element at index "<<j<<" of array B is "<<arrB[j]<<endl;

cout<<"Enter your Choice"<<endl;

cin>>choice;

}while(choice=='Y');

return 0;

Task#8
#include <iostream>

using namespace std;

int main(){

double arr1[10]={10,20,30,40,50,60,70,80,90,100};

int a=0;
for (int i=0;i<10;i++){

cout<<arr1[i]<<endl;

a=a+arr1[i];

cout<<"total sum = "<<a<<endl;

system("pause");

return 0;

cout<<" The element at index "<<j<<" of array B is "<<arrB[j]<<endl;

cout<<"Enter your Choice"<<endl;

cin>>choice;

}while(choice=='Y');

return 0;

}
Task#9
#include <iostream>

using namespace std;

int main()

int arr1[10]={5,3,2,7,8,4,4,2,9,0};

int a;

for (int i=0;i<10;i++){

cout<<arr1[i]<<endl;

cout<<"after swaping of elements"<<endl;

a=arr1[0];

arr1[0]=arr1[8];

arr1[8]=a;

a=arr1[1];

arr1[1]=arr1[9];

arr1[9]=a;

for (int i=0;i<10;i++){

cout<<arr1[i]<<endl;

}
cout<<"size of array = "<<sizeof(arr1)/sizeof(arr1[0])<<endl;

system("pause");

return 0;

Task #10
#include <iostream>

using namespace std;

int main()

int flag=0;

int a;

int arr1[10];

cout<<"enter values of elements"<<endl;

for (int i=0;i<10;i++){

cin>>arr1[i];

cout<<"enter value to search in array "<<endl;

cin>>a;

for (int i=0;i<10;i++){


if (a==arr1[i]){

cout<<"index at "<<i<<endl;

flag=1;

if (flag==0){

cout<<"value not found"<<endl;

system("pause");

return 0;

Task#11
#include <iostream>

#include <string.h>

using namespace std;

int main(){

char a[30]="check";

char b[10]={'a','b','c','\0'};
char c[30];

cout<<"lenght of string a"<<strlen(a)<<endl;

cout<<"concetenating strings "<<strcat(a,b)<<endl;

cout<<"copying string a in string c"<<strcpy(c,a)<<endl;

cout<<c;

system("pause");

return 0;

END

You might also like