Member Avatar for pepsi123

I'm struggling with C++, especially when it's about sorted list. Do they work like arrays? This is what I'm trying to do:
1. Student applicants will now be stored in a link-based sorted list.
2. Student applicants will be organized into two lists: one for female applicants, and one for male. As information for each student is created, these two lists will be created in the client.
3. A new function (clearNames) should be created. The purpose of this function is to check for any students who have not paid their deposits by a certain date. If a student hasn’t paid it by the date specified, then they are removed from the list.
I was going to originally place this in my main, but thinking again I thought it would be easier to place it in the implemenation I have listed below.

#include "Applicant.h"

/* set name and get name*/
void Applicant::setName(string firstName, string lastName)
{
        name = firstName + " " + lastName;
}
string Applicant::getName()
{
        return name;
}
/* set hours and get hours*/
void Applicant::setHours (int newHours)
{
        hours = newHours;
}
int Applicant::getHours()
{
        return hours;
}
/*set deposit and get deposit*/
void Applicant::setDeposit(bool  newDeposit)
{
        deposit = newDeposit;
}
bool Applicant::getDeposit()
{
        int paid;
        if (paid == 200)
                return true;
        else
                return false;
}
/*Set and get payMonth*/
void Applicant::setPayMonth(int newPayMonth)
{
        payMonth = newPayMonth;
}
int Applicant::getPayMonth()
{
        return payMonth;
}
/* Set and get payDay*/
void Applicant::setPayDay(int newpayDay)
{
        payDay = newpayDay;
}
int Applicant::getPayDay()
{
        return payDay;
}
/* Set and get housing*/
void Applicant::setHousing(string newHousing)
{
        housing = newHousing;
}
string Applicant::getHousing()
{
        return housing;
}
/* Set and get sex*/
void Applicant::setSex(char newSex)
{
        sex = newSex;
}
char Applicant::getSex()
{
        return sex;
}
/* Add any necessary points to student's RSVP points*/
void Applicant::addPoints(int gpa)
{
        int addpoints=0;
        int crdhours=0;
        if (gpa >= 3.80)
                addpoints = addpoints+20;
        else  if (gpa >= 3.50)
                        addpoints = addpoints+18;
                else if (gpa >= 3.20)
                                addpoints = addpoints+16;
                        else if (gpa >= 3.00)
                                        addpoints = addpoints+14;
                                else if (gpa >= 2.80)
                                                addpoints = addpoints+12;
                                        else if (gpa >= 2.60)
                                                        addpoints = addpoints+10;
                                                else if (gpa >= 2.40)
                                                                addpoints = addpoints+8;
                                                        else if (gpa >= 2.20)
 addpoints = addpoints+6;
                                                                else if (gpa >= 2.00)
                                                                                addpoints = addpoints+4;
        else
                addpoints = addpoints+2;
        if (crdhours <= 29)
              crdhours = crdhours+10;
        else if (crdhours <= 59)
                        crdhours = crdhours+8;
                else if (crdhours <= 59)
                                crdhours = crdhours+6;
                        else if (crdhours >= 90)
                                        crdhours = crdhours+4;
        points = addpoints+crdhours;
}
/* Deduct any points from student's RSVP points*/
void Applicant::deductPoints(int minuspoints)
{
        int infractions;
        minuspoints = 2*infractions;
        points = points - minuspoints;
}
/*Get the total points for the student*/
int Applicant::getPoints()
{
        return points;
}

There is no one way to create lists. Some are implemnted using arrays, and they will have the underlying attributes of arrays. Many lists are created using user defined types generically called structs/classes, which by your post, you know at least something about. These types are frequently called nodes. A node will contain data and one (or more) pointers to the same type. You can either use a pointer declared in main() to keep track of the list (C style list) or you can declare a struct/class to encapsulate an abstract list. I assume your list is encapsulated in a class.

Under that assumption you can "sort the list" by inserting each new Applicant in the proper spot when as you create it and you can remove any given Applicant when it's indicated. Methods to do this belong in the list class and not in the Applicant class. A search function to find where you want to insert the new Applicant and identify the Applicant you want to remove. You will need to sort the list by looking at some attribute of Applicant (alphabetical by name or by an ID number are common attributes to use).

Insert:
1) find where it insert new Applicant
2) point the new Applicant to the node that will follow it
3) point the node before the new Applicant to the new Applicant.

Delete a given Applicant:
1) find Applicant to delete
2) assign the node to the left of Applicant to delte to the node to the right of the Applicant to delete
3) assign null to the pointer(s) in the Applicant to delete
4) delete the desired Applicant

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.