Last active
July 30, 2017 17:25
-
-
Save TILhub/0a17768dfc4b7b370f7ab320f14e0303 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<fstream> | |
#include <sstream> | |
#include<iostream> | |
#include<vector> | |
#include<string> | |
#include <sys/stat.h> | |
#include <unistd.h> | |
#include<ctime> | |
#include<conio.h> | |
using namespace std; | |
class soding{ | |
public: | |
soding() | |
{ | |
char ch[10]="name_list"; | |
if(exists_test(ch)==0) | |
ofstream outfile(ch); | |
} | |
void instructions() | |
{ | |
cout<" SODING: INDIVIDUAL ASSIGNMENT \n"; | |
cout<<"1: Create Task \n"<<endl; | |
cout<<"2: Edit Task \n"<<endl; | |
cout<<"3: Delete Task \n"<<endl; | |
cout<<"4: List All Task \n"<<endl; | |
cout<<"5: Quit \n\n\n"<<endl; | |
} | |
void selection() | |
{ | |
int s=0; | |
instructions(); | |
cin>>s; | |
if(cin.fail()){cout<<"Illegal Option\n";s=0; | |
} | |
char str[100]; | |
switch(s){ | |
case 1:{cout<<"Task Name: ";cin>>str;create(str);break;} | |
case 2:{cout<<"Task Name: ";cin>>str;edit(str);break;} | |
case 3:{cout<<"Task Name: ";cin>>str;del(str);break;} | |
case 4:{list_file_name();break;} | |
case 5: exit(0); | |
case 6:{cout<<"Task Name: ";cin>>str;show(str); | |
break; | |
} | |
default: cout<<"Illegal Option"; | |
} | |
} | |
void show(const char str[100]) | |
{ | |
string st; | |
ifstream ifs(str); | |
while(getline(ifs,st)) | |
cout<<st; | |
} | |
inline bool exists_test (char name[100]) | |
{ | |
string s=string(name); | |
struct stat buffer; | |
return (stat (s.c_str(), &buffer) == 0); | |
} | |
void create(char str[100]) | |
{ | |
bool test=exists_test(str); | |
if(test==true) | |
{ | |
cout<<"File Already Exists!"<<endl; | |
getch(); | |
system("cls"); | |
instructions(); | |
} | |
else | |
{ | |
ofstream outfile(str); | |
cout<<"Task Created!\n"; | |
getch(); | |
outfile.close(); | |
ofstream ofs; | |
ofs.open("name_list", fstream::in | fstream::out | fstream::app); | |
ofs<<str<<"\n"; | |
ofs.close(); | |
} | |
} | |
void edit(char str[100]) | |
{ | |
char flag; | |
int i=0; | |
string content; | |
int f=exists_test(str); | |
if(f) | |
{ | |
cout<<"Enter content of your task"<<endl; | |
fflush(stdin); | |
getline(cin,content); | |
ofstream ofs; | |
ofs.open(str, fstream::in | fstream::out | fstream::app); | |
time_t timev; | |
time(&timev); | |
ofs<<timev<<"\n"; | |
ofs<<content<<"\n"; | |
ofs.close(); | |
} | |
else | |
{ | |
cout<<"File dosen't exist\n"<<endl; | |
cout<<"Do you want to create task with the file name: "<<str<<"\npress y/n"<<endl; | |
cin>>flag; | |
if(flag=='y'||flag=='Y') | |
create(str); | |
else | |
return; | |
} | |
} | |
void del(char str[100]) | |
{ | |
if( remove(str) != 0 ) | |
perror( "Error deleting file" ); | |
else | |
puts( "File successfully deleted" ); | |
} | |
void list_file_name() | |
{ | |
string st; | |
cout<<"Created Task:\n"; | |
ifstream ofs; | |
ofs.open("name_list"); | |
while(getline(ofs,st)) | |
cout<<st<<endl; | |
getch(); | |
} | |
}; | |
int main() | |
{ | |
//cout<<"ASSIGNMENT " | |
while(1) | |
{ | |
system("cls"); | |
soding sos; | |
sos.selection(); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment