Pointer to an array

I just need help on how to create a pointer to a list of students and make it a private member of the class. This for my data structures class and is our Program #2, which will be derived from Program #1, which I put the partial code for it down below. Thanks for all your help.

Write a C++ object-oriented program to manage a file system for students:
First Name – string
Last Name – string
Student ID – unsigned integer
Email – string
GPA - float
The program will manipulate the student list based on students from the file students.dat
Class requirements
1. Create a student class or struct based on the student structure
2. Create a students class which contains two private members – a pointer to a list of students and a function to print a student’s record. The students class will also provide the following functionality.
a. Load data from a data file into a student list
b. Retrieve and print a student from the student list
c. Insert a student into the student list
d. Delete a student from the student list
e. Print the contents of a student record
f. Print the contents for a list of students
g. Sort the student list by last Name
h. Sort the student list by GPA
Processing requirements
1. Load the students file students.dat
2. Create a menu to carry out the given operations
3. Implement input validation to avoid erroneous program errors
Structure of the file
students.dat – First Name, Last Name, Student ID, Email, GPA
Smith Jefferey 891789 j.smith@spartans.nsu.edu 3.75
Lee Jackson 3678902 j.lee@spartans.nsu.edu 3.66
Gonzales Mariana, 168790 m.gonzales18@spartans.nsu.edu 4.0
Jones Mike 8973125 m.jones143@spartans.nsu.edu 3.1
Williams Anita 2985465 a.williams@spartans.nsu.edu 3.64
Ronsinson Taylor 3278976 t.robinson@spartans.nsu.edu 3.55
Clark Allen 1094567 a.clark@spartans.nsu.edu 3.48
Turner Tavon 318796 t.turner@spartans.nsu.edu 3.2
Jenkins Nelson 289563 n.jenkins@spartans.nsu.edu 3.0


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Name: Mysia Elliott
// Date: September 4th, 2018
// Class: Fall 2018 - Data Structures - CSC 372 - SEC 01 - 78142
// Professor: Dr. Graham
// Program Description: This program uses knowledge of structs and classes to manage a file system for students at Norfolk State University. 
// The program will also manipulate the student list based on student information from a file written into an array. 

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

struct studentInfo // Definition of struct named studentInfo
{
	string firstName; // Variable that holds a student's first name
	string lastName; // Variable that holds a student's last name
	unsigned int studentID; //Variable that holds a student's student ID
	string email; // Variable that holds a student's e-mail
	float gpa; // Variable that holds a student's GPA
};

class studentsProc // Definition of class named studentsProc
{
	public:
		void loadList(); // Function that loads data from a data file into a student list
		void retrieveStudent(); // Function that retrieves and prints a student's information from the student list
		void insertStudent(); // Function that inserts a student's information into the student list
		void deleteStudent(); // Function that deletes a student's information from the student list
		void printStudent(); // Function that prints the contents of a student's record
		void displayStudentList(); // Function that prints the contents for a list of students
		void sortLastName(); // Function that sorts the student list by students' last names
		void sortGpa(); // Function that sorts the student list by GPA
		void studentList(); // Function that displays list of students' names the user can choose from
		studentsProc(); // Constructor
	
	private:
		studentInfo students[40]; // Array of type studentInfo containing student's information
		int size; // Size of the array
		void printList() const; //Print the contents of the list
};

Last edited on
are you sure you want an array? It says list, which usually implies linked list?

you almost never really want a pointer to an array.
if you do, it looks like this..

thing ** p2a = &thingarray; // a pointer to an array. this is probably just adding a layer of ugly for no good reason.

normally you just want this:
thing * pa = thingarray; // more or less this is a reference: pa[0] IS thingarray[0]
or
thing * = new thing[max_size]; //forget the array, and just have a pointer. remember to destroy it in your destructor.

these are just types and variables that you can put in the private area of your class. Its the same as you have seen for any variable in that section.

does this help, or am I not understanding your question?


Last edited on
i'm sorry, i think you are right, can you help with a pointer to a linked list?
If you google "linked list C++" you will get tons of hits also if you search for this on YouTube
thank you
the 10 cent basic version is this:

1
2
3
4
5
6
7
8
9
10
11
12
13
class list
{
   data somedata;
   list * next;
    
   //and some functions..
    insert, delete, find-display, find-modify, is-empty(if needed)... etc

the idea is that each item has a chain to another of the same type,
 for as many of them as you have.   You will see this in the info when 
you research them.  

};


and then your main class with have a list* inside, and that main class' methods will add/delete/find and modify/ find and print/ etc as needed.

I highly suggest you do the list as a totally distinct project and get it working, and once you are satisfied, then add it to the other class and use it.



Last edited on
Topic archived. No new replies allowed.