Professional Documents
Culture Documents
Lab NO:01
FA20-EEE-012
Registration Number
Class EEE-3
5.1. Write a program that declares a structure to store book Id, price and pages of a book. The
structure should include functions to assign user defined values to each book and display the record
of most costly book.
#include <iostream>
int n;
struct Book
Bookprice; int
assign_value(int n)
int i;
for(i=0;i<n;i++)
Price:"; cin>>pk[i].Bookprice;
cin>>pk[i].BookNop;
void display(int n)
{ int
j,k,i;
float lar=pk[0].Bookprice; for(k=0;k<j;i++)
if(pk[i].Bookprice>lar)
lar=pk[i].Bookprice;
j=k;
Book: "<<pk[j].BookNop<<endl;
int main()
return 0;
5.2. Write a program to take the values of two integers and use pointers to add 10 to the value of
each integer.
#include <iostream>
using namespace std;
int main()
*ptr=*ptr+10;
cout<<"after adding 10 to number 2 using pointer";
cout<<"\nthe value of Number 2:"<<n2;
return 0;
5.3. Write a function that swaps the values of two integer variables
#include <iostream>
swap_int(int a,int b)
{
int k;
k=a; a=b;
b=k;
int main()
return 0;
}
5.3 Write a function that swaps the values of two integer variables
#include <iostream>
int k;
k=*a;
*a=*b;
*b=k;
}
int main()
return 0;
}
6. Home Tasks
6.1. There is a structure called employee that holds information like employee code, name, date of
joining. Write a program to create an array of the structure and enter some data into it. Then ask the
user to enter current date. Display the names of those employees whose tenure is 3 or more than 3
years according to the given current date.
#include <iostream>
#include <cstring>
#include <cmath>
struct employee
int code;
string name;
int DD,MM,YYYY;
};
int main(){
int DD,MM,YYYY;
for(int K=0;K<3;k++){
if(abs(emp[k].YYYY-YYYY)>=3)
cout<<emp[k].name<<endl;
return 0;
}
6.2. Write a function to sort data (in increasing order) in an array using
int main()
{
const int arraySize = 10; int a[ arraySize ] =
{3,9,2,7,48,21,15,98,75,67};
selectionSort( a, arraySize );
6.3. Write a program that inputs a string value from the user and displays it in reverse using pointer.
#include <stdio.h>
#include <string.h>
{ int l,
i;
l = strlen(str);
begin_ptr = str; end_ptr
= str;
end_ptr++;
ch = *end_ptr;
*end_ptr = *begin_ptr;
*begin_ptr = ch;
begin_ptr++; end_ptr--;
int main()
return 0;
}
Conclusion:-
In this lab I learned the basic concept such as structures,
pointers, passing function arguments by value and by reference.
However, I also learn the operator asterisk (*) to use as pointer. It
is also used to input the value in the variable and process the data
stored in the variable.