This is a c++ program that reads a file calendar.txt. Then, if Iinput the word \
ID: 3607964 • Letter: T
Question
This is a c++ program that reads a file calendar.txt. Then, if Iinput the word "List" and the optional date, this function showsall events sorted by date in the current month according to theoptional Year and Month.
For example,
$List 2000 11
[Evt] 2000-11-09 Peter’s birthday party.
[Evt] 2000-11-12 Project meeting at 12:30PM.
[Evt] 2000-11-12 Sport hour: volley with John.
[Evt] 2000-11-25 National holiday.
If Year and Month are not specified, all the events of the currentmonth will
be shown on screen. For example,
$List
[Evt] 2008-12-05 Homework #3 due.
[Evt] 2008-12-12 Project meeting at 03:30PM.
[Evt] 2008-12-24 Xmas party.
The content of the file calendar.txt is like follows:
2000-11-25 National holiday.
2008-12-12 Project meeting at 03:30PM.
2000-11-09 Peter’s birthday party.
2000-11-12 Sport hour: volley with John.
2008-12-05 Homework #3 due.
2000-11-12 Project meeting at 12:30PM.
2008-12-24 Xmas party.
Here is my program so far:
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <cstring>
using namespace std;
int *expand(int *arr, int &size, int buf)
{
int *newarr = new int [size+1];
for(int i=0; i<size; i++)
newarr[i] = arr[i];
newarr[size] = buf;
size++;
delete [] arr;
return newarr;
}
void splitstring(string str, string seperater, string &first,string &second) //will split a string into 2
{
int i = (int)str.find(seperater); //findseperator
if(i != -1)
{
int y =0;
if(!str.empty())
{
while(y != i)
{
first += str[y++]; //creating first string
}
y = y+(int)seperater.length(); //jumping forward seperaterlength
while(y != str.length())
{
second += str[y++]; //creating second string
}
}
}
else
{
first =str;
second ="NULL"; //if seperator is not there then second string == null
}
}
int main()
{
string a, b, c;
ifstream infile;
infile.open ("calendar.txt");
if (infile.is_open())
{
cout<< "Please write the function you want to use: " <<endl;
cout<< "(List YYYY-MM, List or Quit to exit)" << endl;
cout<< "$";
stringoption;
getline(cin,option);
a.assign(option);
splitstring(a, " ", b, c);
if (b =="List")
{
if(c != "NULL")
{
//Here it should print the list of activities of the indicatedmonth sorted by date
}
if(c == "NULL")
{
//Here it should print the list of activities of that month sortedby date
}
}
if(b!="List" && b!="Quit")
{
cout << "[Err] Wrong command! Please read the instructionmanual." << endl;
}
infile.close();
}
system ("PAUSE");
return 0;
}
If you can help me I'll rate it Lifesaver... Thanks!
Explanation / Answer
This is a c++ program that reads a file calendar.txt. Then, if Iinput the word \
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.