Professional Documents
Culture Documents
OBJECTIVES :
Introduction to C++ language and its syntax and its coding on codeblocks IDE.
Relation of C and C++ language.
Structures in C++ and its syntax and basic concepts about it.
Difference between passing arguments by value and by reference in C++.
C++ have compatibility with C. Virtually, every error-free C program is a valid C++
program. Depending on the compiler used, every program of C++ can run on a file
with .cpp extension..
INTRODUCTION.:
IN LAB TASKS
TASK # 1 :
Write a program that declares a structure to store date. Declare an instance of this
structure to represent date of birth. The program should read the day, month and year
values of birth date and display date of birth in dd/mm/yy format.
TASK CODE :
OUTPUT :
TASK # 2 :
Write a program that declares a structure to store Student data containing his name , age
and Roll#. Use array of structures to represent record of 3 students.
TASK CODE :
1 #include <iostream> //Standard library
2 using namespace std;
3
4 struct student_data //Declaration of structure
5 {
6 //Declaration of variables and names
7
int age ;
8
char name[25] ;
9
int reg_no;
10
};
11
12
int main()
13
{
14
int i; //Declaration of for loop counter
15
student_data P[3];
16
for(i=1 ; i<=3 ; i++) //For loop for array to take data for 3 students
17
{
18
//Taking inputs for 3 students
19
cout << "Student " << i <<" data";
20
21
cout << "\nEnter student name : ";
22
cin >> P[i].name;
23
cout << "Enter student age : ";
24
cin >> P[i].age;
25
cout << "Enter roll number : ";
26 cin >> P[i].reg_no;
27 cout << "\n\n";
28 }
29 for(i=1;i<=3;i++) //for loop to display records
30 {
31 cout <<"Student " <<i <<" data Record Show"<<endl;
32 cout <<"Name : "<<P[i].name<<endl;
33 cout <<"Age : "<<P[i].age<<endl;
34 cout <<"Registration Number : "<<P[i].reg_no<<endl;
35 }
36 return
OUTPUT :
TASK # 3 :
Write a program that declares a structure to store book name, 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.
TASK CODE :
OUTPUT :
TASK # 4 :
Write a function that swaps the values of two integer variables a. using pass by value b.
and pass by reference and see their differences
TASK CODE :
1 #include<iostream>
2 using namespace std;
3
4 int swap_by_reference(int &,int &);
5 int swap_by_value(int &,int &);
6 int main()
7 {
8 int num_1,num_2;
9 cout<<"Enter Number 1 :";
10
cin>>num_1;
11
cout<<"Enter Number 2 :";
12
cin>>num_2;
13
14
cout<<"\nBefore swapping : \nNumber 1 = "<<num_1<<"\nNumber 2 =
15
"<<num_2<<endl;
16
17
swap_by_reference(num_1,num_2);
18
swap_by_value(num_1,num_2);
19
}
20
int swap_by_reference(int & x,int & y)
21
{
22
int a;
23
a=x;x=y;y=a;
24
cout<<"\nAfter swapping by reference : \nNumber 1 = "<<x<<"\nNumber 2 = "<<y;
25
}
26
27
int swap_by_value(int& a,int & b)
28
{
29
int d;
30
d=a;a=b;b=d;
31
cout<<"\nAfter swapping by value : \nNumber 1 = "<<a<<"\nNumber 2 = "<<b;
32
cout<<"\n\n";
33
}
34
OUTPUT :
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
TASK CODE :
OUTPUT :
LAB CONCLUSION :
Understanding the logics of programs and implementing in C++ coding to design a
program.
We work on detail about structure that is structure is a collection of simple variables.
The variables in a structure can be of different types: Some can be int, some can be
float, and so on.The data items in a structure are called the members of the structure.
Revision of c programming concepts and their use in C++
Functions are one of the fundamental building blocks of C++ so we revised again the
concepts of functions.
Passing arguments to function by value and by reference and understanding the
difference between them.
.
------------------------------------------------------------------------------------