How would I convert two arrays in this header file into a struct? #ifndef STUDEN
ID: 3653784 • Letter: H
Question
How would I convert two arrays in this header file into a struct?
#ifndef STUDENTS_H
#define STUDENTS_H
#include <string>
struct Student
{
std::string studentNames;
int studentCredits;
};
Student numStudents;
// Initialize all student data, allowing for at least the indicated
// number of students
void initializeStudents(int maxStudents);
// Clean up student data
void cleanUpStudents();
// Add a student, starting with 0 credits. Return position where
// inserted.
int addStudent (std::string studentsName);
// Add a number of credits taken by a student
int addCredits (std::string studentName, int credits);
#endif
Explanation / Answer
//you'll have to use pointers for dynamic arrays, and maybe add a size member to that structure...or just make static array with lots of elements. struct Student { std::string *studentNames; int *studentCredits; int size; }; or struct Student { std::string studentNames[1000]; int studentCredits[1000]; int count; };
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.