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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
#include <iostream>
#include <cstring>
using namespace std;
//model for node, gives node what to store
struct node
{
char title [51];
int date;
char rate[6];
char temp[100];
char data;
char * comment;
node * next;
};
//start prototypes
void welcome(node *& head, node * current, node * previous);
void add(node * &head, node * current, node * previous);
void display(node * head, node * current, node * previous);
void del(node * & head, node * current, node * previous);
int main()
{
node * head = NULL;
node * current = NULL;
node * previous = NULL;
welcome(head,current,previous);
return 0;
}
void del(node * &head, node * current, node * previous)
{
char * option;
cout<<"\t\tPlease type in a key(WORD) to "<<endl;
cout<<"\t\tmatch your search to delete: ";
cin>>option;
cin.ignore(100,'\n');
cout << head->title << endl;
current = head;
previous = head;
while (current && strcmp (current->title, option) != 0)
{
cout<<current->title<<endl;
previous = current;
current = current->next;
}
if (current != NULL)
{
previous->next = current->next;
delete current;
}
}
void welcome(node * & head, node * current, node * previous)
{
char option;
cout<<"\n\t\tWelcome to the Portland Bicycle review!";
cout<<"\n\n\tWould you like to Write a (r)eview, (t)ake out reviews or (d)isplay reviews?: ";
cin>>option;
cin.ignore(100,'\n');
cout<<endl;
if (option == 'r')
{
do
{
add(head,current,previous);
cout<<endl<<"\t\tAdd more? ";
cout<<endl<<"\t\tEnter (y)es or (n)o: ";
cin>>option;
cin.ignore(100,'\n');
if (option == 'n')
welcome(head,current,previous);
else
option = true;
}
while (option);
}
else if (option == 'd')
{
display(head,current,previous);
welcome(head,current,previous);
}
else
del(head,current,previous);
}
void display(node * head, node * current, node * previous)
{
current = head;
while (current != NULL)
{
cout<<endl<<"\t\tTitle: "<<current->title<<endl;
cout<<"\t\tDate (MMDD): "<<current->date<<endl;
cout<<"\t\tSafety Rating: "<<current->rate<<endl;
cout<<"\t\tComment: "<<current->comment<<endl;
current = current -> next;
}
return;
}
void add(node *& head, node * current, node * previous)
{
char option;
if (!head)
{
head = new node;
cout<<"\n\t\tEnter a title: ";
cin.get(head->title,51,'\n');
cin.ignore(100,'\n');
cout<<"\t\tEnter a date mmdd (0601): ";
cin>>head->date;
cin.ignore(100,'\n');
cout<<"\t\tEnter a safety rating * through *****: ";
cin>>head->rate;
cin.ignore(100,'\n');
cout<<"\t\tEnter a short comment: ";
cin.get(head->temp,100,'\n');
head->comment = new char [strlen(head->temp)+1];
strcpy(head->comment,head->temp);
cin.ignore(100,'\n');
current = head;
head->next = NULL;
return;
}
else
{
current = new node;
cout<<"\n\t\tEnter a title: ";
cin.get(current->title,51,'\n');
cin.ignore(100,'\n');
cout<<"\t\tEnter a date mmdd (0601): ";
cin>>current->date;
cin.ignore(100,'\n');
cout<<"\t\tEnter a SAFETY rating * through *****: ";
cin>>current->rate;
cin.ignore(100,'\n');
cout<<"\t\tEnter a short comment: ";
cin.get(current->temp,100,'\n');
current->comment = new char [strlen(current->temp)+1];
strcpy(current->comment,current->temp);
cin.ignore(100,'\n');
current->next = head;
head = current;
}
}
|