“”grade””:”” << rand() % 51 + 50 <<“”}””;
int i = 0;
while ( file ) {
getline(file
Assume you just started at a company, and you are tasked with your first feature.
At this company, they use CMake, RapidJson and GoogleTest. CMake is a build tool that helps resolve dependencies and build the project. RapidJson is used to parse JSON files. GoogleTest is a testing framework. Your first task at this company is to take their existing student sorting library and change the sorting algorithm that is being used. The current sorting algorithm grabs the student data from the data/students.json file and uses the built in sorting library that comes with the system. Your boss wants you to change the sorting algorithm to one built in house for “performance and cost concerns”. You have already explained that the built in one should be good enough. But you don’t want to make too many waves so you decide to implement one that you learned in school.
Pick any sorting algorithm that you feel would work, but be prepared to defend it. Add to the documentation comment above your functions explaining your algorithm.
You will also need to write unit tests for your sorting algorithm, which can be found in the test/sort_test.cpp
sort.cpp
#include “sort.h”
#include “rapidjson/document.h”
#include “rapidjson/filereadstream.h”
#include
using namespace rapidjson;
using namespace std;
/**
* Implement this function
*/
void sort_students(list
list
Document document;
document.ParseStream(is);
const Value& arr = document;
list
for (SizeType i = 0; i < arr.Size(); i++) {
student s;
s.name = arr[i][“name”].GetString();
s.grade = arr[i][“grade”].GetInt();
students.push_back(s);
}
fclose(fp);
sort_students(students);
return students;
}
sort_test.cpp
#include “sort.h”
#include
using namespace std;
namespace {
/**
* Add a test here using GoogleTest library
*
* The test itself should verify that all of the students
* are sorted by grade in descending order.
*/
TEST(SortTest, SortShouldSortStudentsJsonByGrade) {
list
}
create_json.cpp
#include
using namespace std;
int main() {
ifstream file(“first-names.txt”);
ofstream out(“students.json”);
string line;
out << “[“;
if ( file.is_open() ) {
getline(file, line);
out << “{“name””:”””” << line << “”””
int i = 0;
while ( file ) {
getline(file