typedef double ListType;
struct Node
{
ListType data;
Node *next;
};
class List
{
public:
List();
~List();
ListType ListMean();
int ListRange(ListType High, ListType Low);
int ListCount();
ListType ListLow();
ListType ListHigh();
bool ListAdd(ListType Grade);
ListType ListSum();
private:
Node *head;
ListType high;
ListType sum;
ListType mean;
int count;
};
List.cpp
#include "List.h"
#include<iostream>
List::List()
{
head = NULL;
}
bool List:: ListAdd(ListType Grade)
{
Node *current;
Node *temp;
List();
if(head == NULL)
{
head = new Node;
head ->data = Grade; //Puts the data in the new node
head->next = NULL;
return true;
}
else
{
current = head;
while(current ->next != NULL)
current = current ->next;
temp = new Node;
temp->data = Grade;
temp->next = NULL;
current->next = temp;
return true;
}
return false;
}
int List::ListCount()
{
count = 0;
//Assume P points to the first node in the list
for (Node * curr = head; curr != NULL; curr = curr->next)
count++;
return count;
}
ListType List::ListHigh()
{
Node *current= head;
double lowest = 0, highest = 0;
lowest = highest = current->data;
while(current->next != NULL)
{
if (current->data < lowest)
lowest = current->data;
else if (current->data > highest)
highest = current->data;
current = current->next;
}
return highest;
}
ListType List::ListLow()
{
Node *current= head;
double lowest = 0, highest = 0;
lowest = highest = current->data; //assign current ptr value to both lowest and highest
while(current->next != NULL)
{
if (current->data < lowest)
lowest = current->data;
else if (current->data > highest)
highest = current->data;
current = current->next;
}
return lowest;
}
ListType List::ListMean()
{
ListType total = 0;
for (Node * curr = head; curr != NULL; curr = curr->next)
total += curr->data;
mean = total / count;
return mean;
}
int List::ListRange(ListType High, ListType Low)
{
int grade_count = 0;
for (Node * curr = head; curr != NULL; curr = curr->next)
{
if( curr->data <= High && curr->data >= Low)
grade_count++;
}
return grade_count;
}
ListType List::ListSum()
{
for (Node * curr = head; curr != NULL; curr = curr->next)
sum += curr->data;
return sum;
}
List::~List()
{
}

New Topic/Question
Reply




MultiQuote





|