-
Notifications
You must be signed in to change notification settings - Fork 0
/
4waysofdisplayingarray.cpp
101 lines (77 loc) · 1.73 KB
/
4waysofdisplayingarray.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
using namespace std;
class student{
int age;
public:
// void getdata();
student();
student(int);
void display();
};
/*void student::getdata(){
cout<<"\nenter the age: ";
cin>>age;
} */
student::student(){
age=0;
}
student::student(int age){
int a;
age=a;
}
void student::display(){
cout<<"the age is: "<<age<<endl;
}
int main()
{
/*student s1, s2, s3, s4;
s1.getdata();
s2.getdata();
s3.getdata();
s4.getdata();
s1.display();
s2.display();
s3.display();
s4.display(); */
/* student s[10]; //memory wasted because only 3 objects used
int i;
for(i=0; i<3; i++){
s[i].getdata();
}
for(i=0; i<3; i++){
s[i].display();
} */
/* student *s1;
s1=new student;
student *s2;
s2=new student;
student *s3;
s3=new student;
s1->getdata();
s2->getdata();
s3->getdata();
s1->display();
s2->display();
s3->display(); */
student *s[10];
int i; //memory is wasted because 10 pointers are stored but only 3 used
s[i]=new student(34);
i++;
s[i]=new student(24);
i++;
s[i]=new student(28);
i++;
// int i;
/* for(i=0; i<3; i++){
s[i]->getdata();
} */
for(i=0; i<3; i++){
s[i]->display();
}
return 0;
}