Home > database >  Bosses consult
Bosses consult

Time:05-21

Distress
//note: can only modify on the original sentence, and don't add or delete statements, ontology contains a total of six errors, # include & lt; iostream>
#include
using namespace std;
The class StudentArray;
The class Student {string name;//name int the age;//age double score;//score public: void input (); Friend class StudentArray;//will StudentArray statement as friend metaclasses, convenient operating}; Void Student: : input () {cout & lt; <"Please enter the student's name:"; Cin & gt;> The name; Cout & lt; <"Please input the student age:"; Cin & gt;> The age; Cout & lt; <"Please enter the student achievement:"; Cin & gt;> Score; } class StudentArray {Student * p;//dynamic array pointer int len.//the length of the array int last;//the last element array subscript public: StudentArray (int length=0). ~ StudentArray (); StudentArray (StudentArray & amp; Arr); StudentArray& Operator=(StudentArray & amp; Arr); Void the add (Student & amp; S);//add s into the array object double getaverage ();//the average of all grades}; StudentArray: : StudentArray (int length=0) {len=length; The last=1; If (len & gt; 0) p=new Student (len); The else p=NULL; {} StudentArray: : ~ StudentArray () the delete [] p; } StudentArray: : StudentArray (StudentArray & amp; Arr) {len=arr. Len; The last=1; P=new Student (len); For (int I=0; i <=last; I++) p [I]=arr. P [I]; } StudentArray& StudentArray: : operator=(StudentArray & amp; Arr) {delete [] p; Len=arr. Len; The last=arr. Last; P=new Student (len); For (int I=0; i <=last; I++) p [I]=arr. P [I]; Return this. } void StudentArray: : add (Student & amp; S) {if (last==len) return;//is full forgo last++ increase; P [last]=s; {} double StudentArray: : getaverage () if (last==1) return 0; double sum=0; For (int I=0; i <=last; I++) sum +=p [I] score; Return the sum/last; } int main () {StudentArray (3) the s1 and s2. Student temp. int i; For (I=0; i <3; I++) {temp. Input (); S1. The add (temp); Cout & lt;
  • Related