calendar.cpp
#include <string>
#include <sstream>
#include <iostream>
#include <vector>
using namespace std;
#include "event.h"
int main(){
// Maximum number of input lines
const int MAX = 100;
// Array of pointers to events
Event *events[MAX];
// Number of currently used pointers in events
int size = 0;
int i = 0;
// Vector containing each input line as a string
vector<string> vec (100);
char temps[100];
while(i < MAX){
cin.getline(temps, 100);
vec[i] = temps;
i++;
}
for(int i = 0; i < vec.size(); i ++){
int found = vec[i].find("/");
int tmo = atoi(vec[i].substr(0, found).c_str());
int sfound = vec[i].find("/", found + 1, 6);
int tda = atoi(vec[i].substr(found + 1, sfound - (found + 1)).c_str());
int tye = atoi(vec[i].substr(sfound + 1, 4).c_str());
string tdes = vec[i].substr(sfound + 6, vec[i].length() - (sfound + 6));
events[size] = new Event(tmo, tda, tye, tdes);
size++;
}
return 0;
}
event.cpp
#include <iostream>
#include <string>
using namespace std;
#include "event.h"
Event::Event(int mo, int da, int ye, string des){
month = mo;
day = da;
year = ye;
desc = des;
}
Event::~Event(){
}
void Event::print(){
cout << month << "/" << day << "/" << year << " " << desc << endl;
}
event.h
#ifndef EVENT_H
#define EVENT_H
#include <iostream>
#include <string>
using namespace std;
class Event{
public:
Event(int mo, int da, int ye, string des);
~Event();
void print();
private:
int month;
int day;
int year;
string desc;
};
#endif
Thank you in advance for your help, gentlemen.

New Topic/Question
Reply




MultiQuote





|