passing array of object to friend function

i am creating a code to implement First Come First Serve cpu scheduling algo here i am passing an array of object to a friend function of class process but my ide is constantly highlighting error while i am trying to access private data member of each object using for loop.The error is between line number 28 to 42

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
 #include<iostream>
using namespace std;

class process
{

private:
	float st,brst_time,fn_time,at;  /*st=start time brst_time=burst time,fn=finish time,at=arrival time*/
	int m;
public:

	void accept()
	{
		cout<<"\nEnter the burst time of the process:-";
		cin>>brst_time;
		at=0;
	}

	void friend calculation(process p[10],int m);
	
};

void calculaion(process p,int m)
{
	float wt,tat,rt;	/* wt=waiting time,tat=turnarround time,rt=response time*/
	for(int j=1;j<=m;j++)
	{
		if(j==1)
		{
			p[j].st=0;
			p[j].fn_time=p[j].brst_time;
		}

		else
		{
			p[j].st=p[j-1].brst_time;
			p[j].fn_time=(p[j-1].fn_time)-(p[j].brst_time);
		}

		p[j].wt=p[j].st-p[j].at;
		p[j].rt=p[j].st-p[j].at;
		p[j].tat=p[j].fn_time-p[j].at;

	}
		float t_wt,t_tat,t_rt;		/* t_wt=total waiting time,t_tat=total turn arround time,t_rt=total response time*/

	
}

	int main()
	{
		process p1[10];
		int n,i;
		cout<<"\nEnter the number of processes:- ";
		cin>>n;
		for(i=1;i<=n;i++)
		{
			p1[i].accept();		
		}
		calculation(p1,n);
                return 0;
	}
Last edited on
A few problems:
1) Line 23, calculation is misspelled.
2) Line 23, The first argument doesn't match the friend declaration. At line 19, the first argument is declared as: process p[10]
3) Lines 40-42: wt, rt, and tat are declared as local variables, not members of the class.
Topic archived. No new replies allowed.