Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

EXPERIMENT NUMBER –Practical 9.

1
STUDENT’S NAME –Balwinder Singh Kalsi
STUDENT’S UID – 21BCS1679
CLASS AND GROUP – 204 A
SEMESTER –1

AIM OF THE EXPERIMENT

LEARN HOW TO USE DYNAMIC MEMORY ALLOCATION IN C++

PROGRAM – Wap to calculate the sum of marks n students of a class inputted


via dynamic memory allocation.

PROGRAM CODE

#include <iostream>
using namespace std;

int main()
{
int size ,i;
int sum=0;
int *ptr;
cout<<"Enter the number of students";
cin>>size;
ptr=new int[size];
for(i=0;i<size;i++)
{
cout<<"Enter Marks";
cin>>ptr[i];
}
for (i=0;i<size;i++)
{
cout<<"Enter marks are"<<endl;
cout<<ptr[i]<<"\n";
}
for(i=0;i<size;i++)
{
sum=sum+ptr[i];
SUBJECT NAME- OBJECT ORIENTED PROGRAMMING
USING C++ LAB
SUBJECT CODE-CSP-152
}

delete[]ptr;
}

PROGRAMS’ EXPLANATION (in brief)

In this program we have studied how to allocate the memory and delete the
memory without using class.

OUTPUT

SUBJECT NAME- OBJECT ORIENTED PROGRAMMING


USING C++ LAB
SUBJECT CODE-CSP-152
Program - Wap to allocate memory dynamically for an object of a class using
class constructor

PROGRAM CODE

#include <iostream>
using namespace std;

class stud {
public:
stud()
{
cout << "Constructor Used" << endl;
}
~stud()
{
cout << "Destructor Used" << endl;
}
};

int main()
{
stud* S = new stud[6];
delete[] S;
}

SUBJECT NAME- OBJECT ORIENTED PROGRAMMING


USING C++ LAB
SUBJECT CODE-CSP-152
OUTPUT

SUBJECT NAME- OBJECT ORIENTED PROGRAMMING


USING C++ LAB
SUBJECT CODE-CSP-152
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. No. Parameters Maximum Marks


Marks Obtained
1. Worksheet Completion including writing 10
learning objective/ Outcome
2. Post Lab Quiz Result 5

3. Student engagement in Simulation/ 5


Performance/ Pre Lab Questions
4. Total Marks 20

SUBJECT NAME- OBJECT ORIENTED PROGRAMMING


USING C++ LAB
SUBJECT CODE-CSP-152

You might also like