Professional Documents
Culture Documents
University Institute of Engineering Department of Mechatronics
University Institute of Engineering Department of Mechatronics
of Mechatronics
Experiment: 3.2
Aim of the practical: LEARN HOW TO USE DYNAMIC MEMORY ALLOCATION IN C++
LIST OF SUB-PROGRAMS-
Practical 9.1: WAP to calculate sum of marks of n students of a class inputted via dynamic memory
allocation.
Solution:
#include <iostream>
#include <conio.h>
{
University Institute of Engineering Department
of Mechatronics
int main( )
University Institute of Engineering Department
of Mechatronics
int sum=0, N;
//clrscr();
cin>>N;
cin>>a[i];
cout<<a[i]<<endl;
delete(a);
getch();
Output:
{
University Institute of Engineering Department
of Mechatronics
Practical 9.2: WAP to allocate memory dynamically for an object of a given class using class’s constructor.
Solution:
#include <iostream>
class stud {
public:
stud()
~stud()
University Institute of Engineering Department
of Mechatronics
};
int main()
delete[] S;
Output:
{
University Institute of Engineering Department
of Mechatronics
• Apply different techniques to decompose a problem and programmed a solution with its sub modules.
• Analyze and explain the behavior of simple programs involving the programming addressed in the
course.
• Implement and evaluate the programs using the syntax and semantics of objectoriented programming.
• Design the solution of real-world problems in order to determine that the program performs as expected.