-
Notifications
You must be signed in to change notification settings - Fork 0
/
use_of_static.cpp
75 lines (74 loc) · 1.23 KB
/
use_of_static.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
#include<iostream>
using namespace std;
class StudentMarks
{
long regNo;
int marks[3];
static int count;
public:
StudentMarks()
{
regNo=123456;
marks[0]=100;
marks[1]=100;
marks[2]=100;
count++;
}
float avg();
void input();
void output();
static int getcount()
{
//return count;
StudentMarks temp;
cout<<"\ncheck;;"<<temp.regNo;
temp.input(); }
};
int StudentMarks::count=0;
void StudentMarks::input()
{
cout<<"enter marks in three subjects(each out of 100)";
for(int i=0;i<3;i++)
cin>>marks[i];
cout<<"enter registration no.";
cin>>regNo;
cout<<endl<<"check;;"<<count<<"\n";
}
float StudentMarks::avg()
{
float total=0.0;
for(int i=0;i<3;i++)
{
total=total+marks[i];
}
return total/3.0;
}
void StudentMarks::output()
{
cout<<regNo<<"\t"<<marks[0]<<"\t"<<marks[1]<<"\t"<<marks[2];
cout<<"\n"<<"total students"<<"\n"<<count;
}
int main()
{
int n;
cout<<"enter no. of students in mark list";
cin>>n;
StudentMarks ob;
ob.input();
ob.getcount();//cannot have this pointer
// StudentMarks::input();
StudentMarks::getcount();
StudentMarks obj[n];
for(int i=0;i<n;i++)
{
obj[i].input();
obj[i].avg();
}
cout<<"REG NO.\tMATHS\tSCIENCE\tENGLISH\n";
for(int i=0;i<n;i++)
{
obj[i].output();
cout<<"\n";
}
cout<<"\n"<<"total students"<<"\n"<<StudentMarks::getcount();
}