#include "apstring.h"
#include <iostream.h>
#include <iomanip.h>

/************ A *************/
// declaring the node
struct NodeA;
typedef node * nodeAptr;
struct NodeA
{
apstring Name;
float Grade;
Node* Next;
};

void a-changegrade(apstring findthisperson, float NewGrade, Node* First)
{
// create a pointer equal to the one passed in
Node* Ref = First;
bool found = true;
// while the name has not been found and the list is not
// at the end
while (found && Ref != NULL)
{
// if the pointer towards the name of the node is the one
if (Ref->Name == findthisperson)
found = true;
// if the person is not found the pointer is redirected to the
// next node
else
Ref = Ref -> next;
}
// change the grade
Ref -> Grade = NewGrade;
}

/*********** B *************/
// declare the node
struct NodeB;
typedef node * nodeBptr;
struct NodeB
{
int jobid;
int priority;
nodeptr next;
};

void insert (int sid, int pr, nodeptr & first)
{
nodeptr ref = first, refprev, newref;
bool found = true;
while (found && ref != NULL)
{
// found if the pointer points to a larger value
if (ref->priority > pr)
found = true;
// otherwise increment the pointers accordingly
// ref points to the next one and refprev points to
// ref
else
{
refprev = ref;
ref = ref -> next;
}
}
// when the spot is found, create a new node
newref = new node;
// set the passed in parameters as the data of new node
newref ->priority = pr;
newref -> jobid = sid;
// have the pointer point to the next largest value
// which was previous found as ref
newref -> next = ref;
// if ref is also the first element of the list
// and since it's larger than the new node, the
// first element is now the new node
// there is no refprev
if (ref == first)
first = newref;
// if the new node is added anywhere else on the list
// the refprev points to the added pointer since ref
// points the already found position
else
refprev -> next = newref;
}

/************* C ****************/
struct node;
typedef node * nodeCptr;
struct node
{
apstring name;
float bill;
bool paid;
nodeptr next;
};

void deletepaidd(nodeptr & first)
{
nodeptr ref = first, refprev, temp;

while (found && ref != NULL)
{
if (ref -> paid = true)
{
temp = ref;
delete ref;
// the first one is deleted
// set the temporary ref to the next one
// and set first as ref
if (ref == first)
{
temp = temp -> next;
first = temp;
}
// otherwise the refprev points to the temp
// and ref points to the next one
else
{
refprev = temp;
ref = temp -> next;
}
}
// otherwise, refprev now points to ref
// and ref points to the next one
else
{
refprev = ref;
ref = ref -> next;
}
}
}

/*************** D ******************/
struct node;
typedef node * nodeptr;
struct node
{
apstring name;
apstring phone;
nodeptr next;
};
void printtelly(nodeptr &first)
{
nodeptr ref=first;
apstring num, myname;

// continues if it is not the end of the list
while (ref != NULL)
{
// sets up the name and the number
num = ref -> phone;
myname = ref -> name;
// if the number begins with 610
// names and numbers are printed out
if (num.substr(0,3) == "610")
cout << myname << " " << num << endl;
// ref is set to point to next node
ref = ref -> next;
}
}

/***************** E ********************/
struct node;
typedef node * nodeptr;
struct node
{
apstring name;
int hours;
nodeptr next;
};

void findavg (nodeptr &first)
{
int hrs = 0, counter = 0;
nodeptr ref=first;

// go through the linked list and add up all the hours
while (ref != NULL)
{
hrs += ref -> hours;
counter++;
ref = ref -> next;
}
// divide hours by the number of students
// recorded by the counter
hrs /= counter;
cout << hrs;
}

/****************** F *****************/
struct node;
typedef node * nodeptr;
struct node
{
apstring name;
double score;
nodptr nextname, nextscore;
};

void print (nodeptr &firstname, nodeptr &firstscore)
{
cout << "Print by name\n";
// this is a doubly linked node and the linkages
// are by alphabetical order and by score
nodeptr myname = firstname, myscore = firstscore;
cout << "Name" << setw(10) << "Score" << endl;
// by name means that it arranges the list by name and prints out
// the name and its score
while (myname != NULL)
{
cout << myname -> name << setw(10) << myname -> score << endl;
myname = myname -> next;
}
cout << "Print by score\n";
cout << "Name" << setw(10) << "Score" << endl;
// by score means that it arranges the list by score and prints
// out the name and its score
while (myscore != NULL)
{
cout << myscore -> name << setw(10) << myscore -> score << endl;
myscore = myscore -> next;
}
}

/*************** G ****************/
struct node;
typedef node * nodeptr;
struct node
{
int userid;
int time;

};

/************* H *******************/
struct node;
typedef node * nodeptr;
struct node
{
int inventory;
apstring itemname;
nodeptr itemnext, numnext;
};
void findnum(nodeptr &firstitem, nodeptr &firstnum, apstring i)
{
int before=0, after=0;
nodeptr item = firstitem, num = firstnum;

// while the item is before the one looked for
// add up all the numbers of items together
while (item -> itemname != i)
{
before += item -> inventory;
item = item -> next;
}
// points to the value after the one that is searched for
// because that is not included in the totaling
item = item -> next;
// continues from there and sums up the number of stuff
// after the searched for item
while (item != NULL)
{
after += item -> inventory;
item = item -> next;
}
// printout
cout << "Before " << before << " After " << after << endl;
}

/************** I ********************/
struct node;
typedef node * nodeptr;
struct node
{
apstring name;
nodeptr nextname;
};
void singlelink (nodeptr &first, apstring ptr)
{
nodeptr ref = firstname, refprev, temp;

while ((ref != NULL) && (ref -> name != ptr))
{
temp = ref;
delete ptr;
refprev = temp;
ref = temp -> next;
}
}
struct node;
typedef node * nodeptr;
struct node
{
apstring name;
int age;
nodeptr nextname, nextage;
};
void doublelink (nodeptr &nextname, nodeptr &nextage, apstring ptr)
{
nodeptr ref1=
}

 

Hosted by www.Geocities.ws

1