-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathList.cpp
More file actions
92 lines (88 loc) · 1.78 KB
/
List.cpp
File metadata and controls
92 lines (88 loc) · 1.78 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <iostream>
using std::cout;
using std::endl;
#include "List.h"
#include "Task.h"
//Creates a new listnode
ListNode::ListNode(const Task &task)
: content( task ), next (0)
{
//empty
}
//gets real task
Task ListNode::getTask() const
{
return content;
}
//constructor
List::List()
{
first = NULL;
bill = 0;
};
//destructor deleting entire list
List::~List()
{
ListNode *pnode;
while (first != NULL)
{
pnode = first;
first = pnode->next;
delete pnode;
}
}
//returns int total charge
int List::getbill()
{
return bill;
}
//insertion taking taskname, parts cost and labor cost
void List::insert( const string &ta, const int i, const int j)
{
//traversing
ListNode *pnode;
Task *task;
//task pointer mallocing space
task = new Task(ta, i, j);
//creates corresbonding task node
pnode = new ListNode(*task);
//pnode inserted before first
pnode->next = first;
//pnode is new first
first = pnode;
//updating bill
bill += i;
bill += j;
}
//only prints first
void List::printfirst() const
{
if (first != NULL) {
//prints single first task
first->getTask().print();
} else {
cout << "no current task"<<endl;
}
}
//prints all tasks
void List::print() const
{
cout << "{{{Printing the vehicle tasks}}}" << endl;
ListNode *pnode;
pnode = first;
if (first == NULL)
{
cout << "No task exists!" << endl;
}
//traverse and print all tasks
while (pnode != NULL)
{
pnode->getTask().print();
cout << " |" << endl;
cout << " |" << endl;
pnode = pnode->next;
}
//total charge
cout << "$Total bill so far: " << bill << endl;
cout << "{{{Bill complete}}}" << endl;
}