I am trying to sort an array of objects by 1 of the objects' properties (3 strings, 1 int, 1 float). I need to sort them by their integers, highest to lowest, and then by their strings, in alphabetical order. I am having trouble understanding how I can access just 1 part of the objects.
Here is all my code, I have included some of the sample code for sorting that was provided.
#include<iostream>
using namespace std;
#include "video.h"
int main() {
const int MAX = 100;
Video *video[MAX]; //up to 100 videos
for(int l = 0; l < MAX; l++)
{
video[l] = NULL;
// cout << video[l] << endl; //testing if all are equal to 0
}
string title;
string url;
string desc;
string sorting;
float length;
int rate;
// cout << "What sorting method would you like to use?" << endl;
getline(cin, sorting);
//cout << "Enter the title, the URL, a comment, the length, and a rating for each video" << endl;
int t = 0;
while(getline(cin, title))
{
getline(cin, url);
getline(cin, desc);
cin >> length;
cin >> rate;
cin.ignore();
video[t] = new Video(title, url, desc, length, rate);
t++;
}
for(int s = 0; s < t; s++){
video[s]->print();
}
for(int e = 0; e < t; e++)
{
delete video[e];
}
// SORTING
if(sorting == "length") {
int q = 0;
bool Video::longer(Video *video)
{ return m_length > other->m_length; }}
else if(sorting == "rating") {
}
else if(sorting == "title") {
for(int r = 0; r < MAX; r++) {
}
else{
cerr << sorting << " is not a legal sorting method, giving up" << endl;
return 1; }
//this sorts the videos by length
for(int last = num_videos -1; last > 0; last--) {
for(int cur = 0; cur < last, cur++) {
if(videos[cur]->loner(videos[cur+1])) {
swap(videos[cure], videos[cur+1]); }}}