#include<iostream>
#include<string>
using namespace std;
class Prerequisites
{
public:
void orderClasses(string* Input);
};
void Prerequisites::orderClasses(string* Input)
{
// Need to find the length of the array Input
}
int main()
{
Prerequisites A;
string classes[]={"CSE121: CSE110",
"CSE110:",
"MATH122:"
};
A.orderClasses(classes);
}
I need to find the length of the array classes[] in the methos orderClasses.
I cannot alter the signature of the method orderClasses ! That is a requirement.
You should pass the number of elements in the array to
orderClasses(). Since that is not an option, consider some alternatives:Prerequisitesto inform it how large the array will be when you do callorderClasses().None of these are good solutions to the problem: the best option while still using an array, of course, is just to pass the array size to the function. In most scenarios, it would be even better not to use an array at all and just pass a
std::vector<std::string>containing the strings.