Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
25 views6 pages

Experiment Number - 2

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 6

EXPERIMENT NUMBER –2

STUDENT’S NAME –Kavita Nainwal


STUDENT’S UID –22BAI70573
CLASS AND GROUP-22AML102/A
SEMESTER –2nd

AIM OF THE EXPERIMENT –


2.1) WAP to input a matrix of dimension m*n. If base address is 1000. Find the address of (m-1,
n-1) element of the matrix.
2.2) Create a class called employee with the following details as variables within it.
1. Name of the employee (string)
2. Age (int)
3. Designation (string) 4. Salary (double)
Write a program to create array of objects for the same to access these. Also, make use of member
functions to accept values and print the name, age, designation and salary.

2.3) WAP to illustrate the use of scope resolution operator. Display the various values of the
same variables declared at different scope levels.

FLOWCHART/ ALGORITHM – 2.1)


1. Initialize variables ad, m, n, base, and add to zero.
2. Prompt the user to enter the number of rows and columns of the matrix.
3. Read the number of rows and columns of the matrix from the user.
4. Prompt the user to enter the matrix.
5. Read the matrix from the user and store it in the array ad.
6. Prompt the user to enter the base address.
7. Read the base address from the user and store it in the variable base.
8. Calculate the size of an integer using the sizeof operator.
9. Calculate the address of the last element in the matrix using the formula add = base + sizeof(int)
* (n * (m - 1 - 0) * (n - 1 - 0)).
10. Print the address of the last element of the matrix.
11. Exit.
2.2)
1. Define a class named "employee" that contains the private data members name_of_employee,
age, designation, and salary, and the public member functions getdata and putdata.
2. Implement the getdata function to prompt the user to enter the name, age, designation, and
salary of an employee, and read and store the values in the corresponding data members of the
employee object.
3. Implement the putdata function to display the name, age, designation, and salary of an employee
object.
4. In the main function, create an array of employee objects named "e" of size 2.
5. Use a for loop to iterate through the array and prompt the user to enter the details of each
employee object by calling the getdata function on each object in the array.

SUBJECT NAME-Object Oriented Programming Using C++ SUBJECT CODE- 22CSH-103


6. After reading the details of each employee object, display the details of each employee object by
calling the putdata function on each object in the array.
7. Exit. 2.3)
1. Declare a global variable "my_variable" and initialize it to 24.
2. Define the main function.
3. Declare a local variable "my_variable" inside the main function and initialize it to 125.
4. Print the value of the global variable "my_variable" using the scope resolution operator (::).
5. Print the value of the local variable "my_variable".
6. Return 0 to indicate successful execution.
7. Exit.

SUBJECT NAME-Object Oriented Programming Using C++ SUBJECT CODE- 22CSH-103


PROGRAM CODE – 2.1
#include <iostream>
using namespace std; int
main ()
{
int ad[100][100]; int
m,n,base=0,add=0;
cout<<"Enter the row and column of the matrix:";
cin>>m; cin>>n; cout<<"Enter the matrix:";
for (int i = 0; i < n; i++)
{
for(int j = 0; j<n; j++)
cin>>ad[i][5];
}
cout<<"Enter the base address=";
cin>>base;
add=base+sizeof(int)*(n*(m-1-0)*(n-1-0));
cout<<"Address="<<add<<endl;
return 0; }
2.2
#include<iostream> using
namespace std;
class employee
{
char name_of_employee[20];
int age; char
designation[10];
double salary;
public:
void getdata();
void putdata();
};
void employee :: getdata()
{
cout<<"Enter the Name of Employee:";
cin>>name_of_employee;
cout<<"Enter the Age:"; cin>>age;
cout<<"Enter the Designation:";
cin>>designation; cout<<"Enter
the Salary:"; cin>>salary;
}
void employee :: putdata()
{
cout<<"Name of employee:"<<name_of_employee<<endl;
cout<<"Age:"<<age<<endl;
cout<<"Designation:"<<designation<<endl;
cout<<"Salary:"<<salary<<endl;

SUBJECT NAME-Object Oriented Programming Using C++ SUBJECT CODE- 22CSH-103

}
int main()
{
employee e[2];
for(int i=0;i<2;i++)
{
e[i].getdata();
e[i].putdata();
}
}

2.3)
#include<iostream>
using namespace std;
int my_variable = 24;
int main()
{
int my_variable = 125;
cout << "Value of global my_variable is " << ::my_variable<<endl;
cout << "Value of local my_variable is " << my_variable<<endl;
return 0;
}

SUBJECT NAME-Object Oriented Programming Using C++ SUBJECT CODE- 22CSH-103

PROGRAMS’ EXPLANATION (in brief):


2.1) This program is used to find the address of (m-1, n-1) element of the matrix.
2.2) This program is used to print the detail of employee by making a class.
2.3) This program is used to display the various values of the same variables declared at different
scope levels.

OUTPUT –
2.1)

2.2)

2.3)

SUBJECT NAME-Object Oriented Programming Using C++ SUBJECT CODE- 22CSH-103


LEARNING OUTCOMES -

. Identify situations where computational methods would be useful.

. Approach the programming tasks using techniques learnt and write pseudo-code.

. Choose the right data representation formats based on the requirements of the
problem.

. Use the comparisons and limitations of the various programming constructs and choose the
right one for the task.

EVALUATION COLUMN (To be filled by concerned faculty only) -

Sr. Parameters Maxim Marks


No. um Obtained
Mark
s

1. Worksheet Completion 10

2. Viva 8

3. Conduct 12

Total Marks 30

SUBJECT NAME-Object Oriented Programming Using C++ SUBJECT CODE- 22CSH-103

You might also like