I'm working on an assignment that provides us with the framework of a code and asks us to make certain changes and program certain things to change it. Right now, I'm just trying to implement one of the given prototype functions, called "readConfig", so that the user can input each of the needed inputs. I keep getting the error: "undefined reference to `readConfig(int&, int&, std::__cxx11::basic_string, std::allocator >&)'".
I've googled around, and it seems this error is from not defining the prototype. From the course material, I am still unsure how exactly I go about defining/implementing the prototype function in order to properly reference it. I don't understand what exactly implementation is asking for. Note that I am not asking anyone to do my assignment, I am only asking for help in learning how to properly define/use prototypes and functions. Please just let me know if I can provide additional information. Here is my code:
/*
* DON'T CHANGE FOLLOWING CODE
*/
#include "SFML/Graphics.hpp"
#include <iostream>
#include <fstream>
#include <string>
const float WIDTH = 550.0; // width of the window for display
const float HEIGHT = 750.0; // height of the window for display
const int FONT_SIZE = 25; // character size
const float LEFT_X = 100.0; // Left X position for label
const float LOW_Y = 700.0; // LOW Y position for label
const float HIGH_Y = 50.0; // HIGH Y position for label
using namespace std;
// Function prototypes - you need to implement
void readConfig(int &numGrades, int &maxInGrade, string &filename);
int findNumInRange(string filename, int low, int high);
void initFrequency(string letters[], int freqLetters[],
int numGrades, string filename);
void setCurves(sf::RectangleShape bars[], sf::Text labels[], int freqLetters[],
string letters[], sf::Font &font, int numGrades, int maxInGrades);
/* DON'T CHANGE THE ABOVE CODE */
int main() {
int numGrades = 5; // number of different letter grades
int maxInGrade = 20; // maximum number of students in any letter grade
string filename; // name of input file containing scores
// STEP 1:
// IMPLEMENT readConfig that initializes (1) numGrades, (2) maxInGrade, and
// (3) filename
//
readConfig (numGrades, maxInGrade, filename);
cout << "Enter the maximum number of letter grades:";
cin >> numGrades;
cout << "Enter the anticipated maximum number of students receiving the same letter grade:";
cin >> maxInGrade;
cout << "Enter the name of the file containing scores:";
cin >> filename;
string letters[numGrades]; // each entry represents string representing the grade
int freqLetters[numGrades]; // each entry records occurrence of grades corresponding
// to the letter grade
// STEP 2:
// IMPLEMENT initFrequency that initializes letters[] and freqLetters[] by processing
// input file (filename).
// You need to replace the following for loop with a call to initFrequency
//
initFrequency (letters, freqLetters, numGrades, filename);
//
// DON'T CHANGE FOLLOWING CODE
//
sf::RenderWindow window(sf::VideoMode(600, 800), "Grade Histogram");
sf::Font font;
font.loadFromFile("resources/arial.ttf");
/* DON'T CHANGE ABOVE CODE */
// You are free to change the following code. However, as it is, it should work
sf::Text min, max;
min.setFillColor(sf::Color::Yellow);
min.setFont(font);
min.setString("0");
min.setCharacterSize(FONT_SIZE);
max.setFillColor(sf::Color::Yellow);
max.setFont(font);
max.setString(to_string(maxInGrade));
max.setCharacterSize(FONT_SIZE);
min.setPosition(LEFT_X-FONT_SIZE*2, LOW_Y-FONT_SIZE);
max.setPosition(LEFT_X-FONT_SIZE*2, HIGH_Y-FONT_SIZE/2);
sf::RectangleShape bars[numGrades];
sf::Text labels[numGrades];
// STEP 3:
// IMPLEMENT setTheCurves and replace the following initialization
// code with a call to setTheCurves
//
float x_incr = (WIDTH - 100)/numGrades;
float x_offset = LEFT_X+FONT_SIZE;
float height_unit_pixels = (HEIGHT - (HIGH_Y + FONT_SIZE)) / maxInGrade;
int count = 0;
for (int i=0; i < numGrades; i++) {
float height = freqLetters[i] > maxInGrade ? maxInGrade : freqLetters[i];
bars[i].setSize(sf::Vector2f(x_incr-50, height*height_unit_pixels));
bars[i].setPosition(x_offset+x_incr/2, LOW_Y);
bars[i].rotate(180);
labels[i].setFillColor(sf::Color::Yellow);
labels[i].setFont(font);
labels[i].setString(letters[i]);
labels[i].setCharacterSize(FONT_SIZE);
labels[i].setFillColor(sf::Color::Red);
labels[i].setPosition(bars[i].getPosition().x-FONT_SIZE, LOW_Y+FONT_SIZE);
x_offset += x_incr;
}
/* DON'T CHANGE THE FOLLOWING CODE */
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
switch (event.type) {
case sf::Event::Closed:
window.close();
break;
default:
window.clear();
window.draw(min);
window.draw(max);
for (int i = 0; i < numGrades; i++) {
window.draw(bars[i]);
window.draw(labels[i]);
}
window.display();
}
}
}
return 0;
}