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
|
#include <iostream>
#include <cctype>
#include <string.h>
#include <stdio.h>
#include <fstream>
#include <string>
//function prototypes
void lists();
void print();
void search();
using namespace std;
//array of structs to hold events
struct events{
char name[100],
location[100],
description[100],
date[100],
attendance[100],
enthusiasm[100];
};
events activity[50];
//identify and use the file to input and retrieve data.
ofstream indata;
ifstream input;
int ans;
char res;
int main(){
//keyword for to search for the right event, search to retrieve the line, position to find the keyword.
char keyword[10];
char search[100];
int position;
indata.open("summer-list.txt");
input.open("summer-list.txt");
do{
lists();
cout << "Would you like to search for an event with a keyword(2) or print(3)" << endl;
cin >> ans;
cin.ignore(100, '\n');
}while(res == 'y');
if(ans ==2){
// search();
}
if (ans == 3){
print();
}
indata.close();
return 0;
}
//Search for a word in the file
void search(){
//cout << "Enter a keyword: " << endl;
// cin >> keyword;
cin.ignore(100, '\n');
int length = strlen(activity[50].name);
//for(int m=0; m< length; m++){
// while(strcmp(keyword, activity[m].name )==0)
//while(!input.eof()){
// input.get(search, 100, '\n');
// input.get(search, 100, input.eof());
//if(position = search.find(keyword ) != string::npos){
// cout << search;
//char c;
//while (is.get(c))
// std::cout << c;
//}
//}
}
//print all events for the user
void print(){
cout<< "Name # Location # Date # Attendance # Enthusiasm " << endl;
for(int s =0; s< 5; s++){
cout << activity[s].name << "\t # " << activity[s].location <<
"\t # " << activity[s].date << "\t # " << activity[s].attendance << "\t # " << activity[s].enthusiasm << endl;
}
}
//add events to the list.
void lists(){
for(int s =0; s < 5; s++){
cout << "Enter the event name: ";
cin >> activity[s].name;
cin.ignore(100, '\n');
indata << activity[s].name << " # ";
cout << "Enter the event loaction: ";
cin>> activity[s].location;
cin.ignore(100, '\n');
indata << activity[s].location << " # ";
cout << "Enter the event date: ";
cin>> activity[s].date;
cin.ignore(100, '\n');
indata << activity[s].date << " # ";
cout << "Enter the event attendance: ";
cin>> activity[s].attendance;
cin.ignore(100, '\n');
indata << activity[s].attendance << " # ";
cout << "Enter the event enthusiasm: ";
cin>> activity[s].enthusiasm;
cin.ignore(100, '\n');
indata << activity[s].enthusiasm << " # " << '\n';
cout << "Would you like to continue to enter events(y/n): ";
cin >> res;
cin.ignore(100, '\n');
if (res != 'y' && res != 'Y'){
break;
}
}
}
|