'error: prototype for ' ' does not match any in class ' ';
I recently started coding in c++ and was doing a project. Currently I'm using multiple files, one as a header, one for cpp code, and one as a main file. I've been stuck on a problem for a while now and I just cant figure out whats wrong. Whenever I compile the cpp file I get the error prototype for ‘GradeCalculator::GradeCalculator(const int*, const int&)’ does not match any in class ‘GradeCalculator’. I would really love to get some help and explanation on whats going wrong, here's my code:
//main file:
#include <iostream>
#include "GradeCalculator.h"
#define NUM_ASSIGNMENTS 100
int main() {
int points[NUM_ASSIGNMENTS];
int newsize = 0;
GradeCalculator gradecalculator(points, newsize);
std::cout << "Grade Calculator\n" << std::endl;
std::cout << "================\n" << std::endl;
std::cout << "This program will calculate your grade average on your assignments.\n" << std::endl;
std::cout << "Your lowest grade will be dropped.\n" << std::endl;
newsize = gradecalculator.addPoints(points);
gradecalculator.printResults(points, newsize);
return 0;
}
//header file:
#ifndef DEMO_GRADECALC_H
#define DEMO_GRADECALC_H
#include <iostream>
class GradeCalculator{
private:
int points[100];
int size;
public:
GradeCalculator(int* points, int size);
int addPoints(int*points);
int dropLowest(int* points, int size);
explicit GradeCalculator(const int* points, const int size);
void printResults(int* points, int size);
virtual ~GradeCalculator();
};
#endif
//cpp file:
#include <iostream>
#include "GradeCalculator.h"
GradeCalculator::GradeCalculator(const int* points, const int &size){
}
int GradeCalculator::addPoints(int* points){
int sizeofarray = 0;
for( int j = 0; points[j] = '\0'; j++){
std::cin >> points[j];
sizeofarray ++;
}
return sizeofarray;
}
int GradeCalculator::dropLowest(int* points, int size) {
int lowest = points[0];
int lowestIndex = 0;
for( int i = 0; i < size; i++ ) {
if( points[i] < lowest ) {
lowest = points[i];
lowestIndex = i;
}
}
for( int i = lowestIndex; i < size-1; i++ ) {
points[i] = points[i+1];
}
return size - 1;
}
void GradeCalculator::printResults(int* points, int size){
dropLowest(points, size);
int newtotal;
for(int k = 0; points[k] = '\0'; k++){
newtotal += points[k];
}
float avg = newtotal/size;
std::cout << "Total Points: " << newtotal << "\n" << std::endl;
std::cout << "Average: " << avg << "\n" << std::endl;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
