Class/Constructor errors

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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# include <iostream>
# include <cstring>
#include <iomanip>
#include <cmath>
using namespace std;


class Course                                               // Creating the class Course
{
public:
char CourseName[10];                                       // Array of size 10, 9 characters and 1 null terminator
int StudentNumber;                                         // Number of students enrolled in the class
double Grade[30];                                          //Grade Array of size 30, the maximum number of students that can be in the class
double Average;

Course(char CName[],int SNumber)                           //Counstructor: CNAME for Course Name and SNumber for Student Number

{
	setCourseName (CName);                                 // Function setCourseName takes as argument the array CName
	setStudentNumber (SNumber);                            // Function setStudentNumber takes as argument the integer value of SNumber provided in the main function
	
	for(int i=0; i<30;i++)                                 // Initializing the whole array to 0.0 (double)
		Grade[i]=0.0;
	
	Average=0.0;                                           // Defaulting average to 0.0 (double)

}


void setCourseName(char CName[])
{   CourseName[0]='\0';
	strncpy(CourseName,CName,9);
	CourseName[9]='\0';

}

void setStudentNumber (int SNumber)                        //Function definition
{
    StudentNumber=(SNumber<8 || SNumber>30?8:SNumber);     // Using the conditional terminator to set the StudentNumber value to 8 if the conditions were true, and to take the value provided if false
}         

char* getCourseName (void)

{
	return CourseName;
}

int getNumberStudent (void)
{
return StudentNumber;
}

double getAverage (void)
{
return Average;
}

void GradeFiller (void)       // SNumber is the number of students in the class=number of grades
{ int i=0;                                                 // Initializing i to 0 to use it in the While loop
	while (i<StudentNumber)                                      // SNumber would change if we ever change the value through the program, making the change easier to apply
	{
		Grade[i]=rand()%101;                               // Rand will provide numbers between 0 and 100 in each cell of the array
		i++;
}
}

void GradeChanger(int k, double grade)
{
	int main; 

	if(k>=0 && k<=29)
		main=k;
	else main=0;

Grade[main]=grade;
}

double AverageCalculator (void)
{
	double sum=0.0;

	for(int i=0;i<StudentNumber;i++)
		sum=Grade[i]+sum;

	static_cast<double> (Average)=sum/StudentNumber;

}

double StandardDeviation (void)
{
	double StdDvtn;
	
	double top=0.0;

	for (int i=0;i<StudentNumber;i++)
	top= top +pow((Grade[i]-Average),2)	;
	

	StdDvtn= sqrt(top/(StudentNumber-1))
	
	
	
	
	;}




int GradeChecker (double Grade[], int SNumber)             // Takes as arguments the array Grade and the number of student SNumber
{
	int counter=0; 
for (int i=0;i<SNumber;i++)
{
	if (Grade[i]>75)                                       // Checking each grade's value if it is > then 75 to incrememnt the counter if true
counter++;

return counter;                                            // The counter is the number of grades above 75

}
}

void printClass (int SNumber, double Grade[])
{
cout<<"Name of the course: "<<CourseName<<endl;
cout<<"Number of Students: "<<StudentNumber<<endl;
cout<<"The Grades of the students are: ";
for (int i=0;i<SNumber;i++)
{
cout<<Grade[i]<<endl;
}
cout<<"The average of the class is: "<<Average;
cout<<"The standart deviation is: "<<StandardDeviation();

}


};






 void main ()
 {

	 Course Class[3]={"Bio",13,"Chimo",23,"Phisio",22};
	 
	 Course a1;

	 for (int i=0;i<3;i++)
	 {
	 Class[i].setCourseName("Hello");
	 Class[i].setStudentNumber(10);
	 Class[i].GradeFiller();
     }
	
	 Course *Ptr=Class;

	 //By using a pointer I need to print on the screen info about the 2nd  and 3rd (using the arrow and the dot operator)
	 //I got a little lost in this part
	 //
	 //
	 //


	 cout<<"The Average of class 1 is: "<<Ptr->AverageCalculator;
	 cout<<"The Average of class 2 is: "<<(Ptr+1)->AverageCalculator;
	 cout<<"The Average of class 3 is: "<<(Ptr+2)->AverageCalculator;

	 cout<<"The Std Deviation for the class 3 is: "<<(Ptr+2)->StandardDeviation;

	a1.Grade[23]=30;


	cout<<"The Course Name of class 1 is : "<<Ptr->getCourseName;
	cout<<"Number of students in class 1 is : "<< Ptr->getNumberStudent;


	cout<<"Number of grades >75: "<<Ptr->GradeChecker;

	 }



Errors: Warning 1 warning C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. c:\users\pc\desktop\usb\anthony\documents\visual studio 2012\projects\csc 213 hw1\csc 213 hw1\p1.cpp 43
Error 2 error C2440: 'initializing' : cannot convert from 'const char [4]' to 'Course' c:\users\pc\desktop\usb\anthony\documents\visual studio 2012\projects\csc 213 hw1\csc 213 hw1\p1.cpp 158
Error 3 error C2440: 'initializing' : cannot convert from 'int' to 'Course' c:\users\pc\desktop\usb\anthony\documents\visual studio 2012\projects\csc 213 hw1\csc 213 hw1\p1.cpp 158
Error 4 error C2440: 'initializing' : cannot convert from 'const char [6]' to 'Course' c:\users\pc\desktop\usb\anthony\documents\visual studio 2012\projects\csc 213 hw1\csc 213 hw1\p1.cpp 158
Error 5 error C2078: too many initializers c:\users\pc\desktop\usb\anthony\documents\visual studio 2012\projects\csc 213 hw1\csc 213 hw1\p1.cpp 158
Error 6 error C3867: 'Course::AverageCalculator': function call missing argument list; use '&Course::AverageCalculator' to create a pointer to member c:\users\pc\desktop\usb\anthony\documents\visual studio 2012\projects\csc 213 hw1\csc 213 hw1\p1.cpp 178
Error 7 error C3867: 'Course::AverageCalculator': function call missing argument list; use '&Course::AverageCalculator' to create a pointer to member c:\users\pc\desktop\usb\anthony\documents\visual studio 2012\projects\csc 213 hw1\csc 213 hw1\p1.cpp 179
Error 8 error C3867: 'Course::AverageCalculator': function call missing argument list; use '&Course::AverageCalculator' to create a pointer to member c:\users\pc\desktop\usb\anthony\documents\visual studio 2012\projects\csc 213 hw1\csc 213 hw1\p1.cpp 180
Error 9 error C3867: 'Course::StandardDeviation': function call missing argument list; use '&Course::StandardDeviation' to create a pointer to member c:\users\pc\desktop\usb\anthony\documents\visual studio 2012\projects\csc 213 hw1\csc 213 hw1\p1.cpp 182
Error 10 error C3867: 'Course::getCourseName': function call missing argument list; use '&Course::getCourseName' to create a pointer to member c:\users\pc\desktop\usb\anthony\documents\visual studio 2012\projects\csc 213 hw1\csc 213 hw1\p1.cpp 187
Error 11 error C3867: 'Course::getNumberStudent': function call missing argument list; use '&Course::getNumberStudent' to create a pointer to member c:\users\pc\desktop\usb\anthony\documents\visual studio 2012\projects\csc 213 hw1\csc 213 hw1\p1.cpp 188
Error 12 error C3867: 'Course::GradeChecker': function call missing argument list; use '&Course::GradeChecker' to create a pointer to member c:\users\pc\desktop\usb\anthony\documents\visual studio 2012\projects\csc 213 hw1\csc 213 hw1\p1.cpp 191
13 IntelliSense: no suitable constructor exists to convert from "const char [4]" to "Course" c:\Users\pc\Desktop\USB\Anthony\Documents\Visual Studio 2012\Projects\CSC 213 HW1\CSC 213 HW1\P1.cpp 147
14 IntelliSense: no suitable constructor exists to convert from "int" to "Course" c:\Users\pc\Desktop\USB\Anthony\Documents\Visual Studio 2012\Projects\CSC 213 HW1\CSC 213 HW1\P1.cpp 147
15 IntelliSense: no suitable constructor exists to convert from "const char [6]" to "Course" c:\Users\pc\Desktop\USB\Anthony\Documents\Visual Studio 2012\Projects\CSC 213 HW1\CSC 213 HW1\P1.cpp 147
16 IntelliSense: too many initializer values c:\Users\pc\Desktop\USB\Anthony\Documents\Visual Studio 2012\Projects\CSC 213 HW1\CSC 213 HW1\P1.cpp 147
17 IntelliSense: no default constructor exists for class "Course" c:\Users\pc\Desktop\USB\Anthony\Documents\Visual Studio 2012\Projects\CSC 213 HW1\CSC 213 HW1\P1.cpp 149


Hello, basically I think I have checked my course and my exercises, but I coudlnt find a good solution to my problem.
I have to create an Array of type Course and then fill its member datas using various member functions.
Those errors are caused by some Constructor defect, which I dont really know what it is. Basically the errors are similar to each others, any help would be much appreciated and thank you.
http://www.eelis.net/iso-c++/testcase.xhtml
_ indent your code
_ the line numbers in the error messages don't seem to correspond to the code that you posted, fix that.
Indentation fixed
Topic archived. No new replies allowed.