Last active
July 21, 2020 21:50
-
-
Save edwin-std/ddf43f71977da661120d2a7d767f2b20 to your computer and use it in GitHub Desktop.
All code-files for "Notebook" program
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
#pragma once | |
#include<stdio.h> | |
#include<iostream> | |
#include<string> | |
#include<vector> | |
#include<iterator> | |
#include<fstream> | |
using namespace std; | |
class Book | |
{ | |
public: | |
char* type; | |
virtual char* Type()=0; | |
virtual void print()=0; | |
virtual void edit()=0; | |
virtual void add(string method) = 0; | |
//virtual void save(ofstream&F)=0; | |
//virtual void load(ifstream&F)=0; | |
}; |
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"cont.h" | |
cont::cont(void) | |
{ | |
type=new char[7]; | |
type="contact"; | |
Name=0; | |
Commentary=0; | |
}; | |
cont::~cont(void) | |
{ | |
if(Name!=0) | |
delete Name; | |
if(Commentary!=0) | |
delete Commentary; | |
Phone.clear(); | |
delete &Phone; | |
}; | |
void cont::setName() | |
{ | |
char c[100]; | |
cout<<"Enter the name"<<endl; | |
cin >> c; | |
Name=new char[strlen(c)+1]; | |
strcpy(Name,c); | |
}; | |
void cont::setCommentary() | |
{ | |
char c[100]; | |
cout<<"Enter the commentary if needed"<<endl; | |
cin >> c; | |
Commentary=new char[strlen(c)+1]; | |
strcpy(Commentary,c); | |
}; | |
void cont::add(string method) | |
{ | |
if (method == "new") | |
{ | |
cout << "Creating new contact" << endl; | |
setName(); | |
setCommentary(); | |
} | |
else if (method == "phone") | |
{ | |
cout << "Creating new phone" << endl; | |
phone*A = new phone; | |
A->add("new"); | |
Phone.push_back(A); | |
} | |
}; | |
char* cont::Type() | |
{ | |
return type; | |
}; | |
void cont::print() | |
{ | |
cout<<type<<endl; | |
int ind = 0; | |
if(Name!="\0") | |
cout << Name << endl; | |
else cout << "No name" << endl; | |
if(Phone.empty()!=true) | |
{ | |
while(Phone[ind]!=Phone.back()) | |
Phone[ind++]->print(); | |
Phone[ind]->print(); | |
} | |
if(Commentary!="\0") | |
cout << Commentary << endl; | |
else cout << "No commentary" << endl; | |
}; | |
void cont::edit() | |
{ | |
int i; | |
print(); | |
while(1) | |
{ | |
cout<<"1 - edit name\n2 - edit phones\n3 - edit commentary\n0 - exit"<<endl; | |
cin>>i; | |
switch(i) | |
{ | |
case 1: | |
setName(); | |
break; | |
case 2: | |
if(Phone.empty()==true) | |
{ | |
cout<<"No phones avaible"<<endl; | |
return; | |
} | |
int j; | |
cout << "Number of phones: " << Phone.size() << endl; | |
cout << "Enter the phone id you want to edit" << endl; | |
cin >> j; | |
if(j < Phone.size()) | |
Phone[j]->edit(); | |
else cout << "This id doesn't exist" << endl; | |
break; | |
case 3: | |
setCommentary(); | |
break; | |
case 0: | |
return; | |
default: | |
cout << "404" << endl; | |
break; | |
} | |
} | |
}; | |
/*void cont::LegacySave(ofstream &F) | |
{ | |
int i=0; | |
F<<"''"<<type<<"'': {"<<endl; | |
F<<"''Name'': "<<"''"<<Name<<"'',"<<endl; | |
F<<"''Commentary'': "<<"''"<<Commentary<<"'',"<<endl; | |
if(Phone.empty()!=true) | |
{ | |
F<<"''Phones'': ["<<endl; | |
while(Phone[i]!=Phone.back()) | |
{ | |
Phone[i++]->save(F); | |
F<<","<<endl; | |
} | |
Phone[i]->save(F); | |
F<<endl<<"]"<<endl; | |
} | |
};*/ |
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"phone.h" | |
class cont: public Book | |
{ | |
public: | |
char* type; | |
char* Type(); | |
cont(); | |
~cont(); | |
char* Name; | |
vector<phone*>Phone; | |
char*Commentary; | |
void print(); | |
void edit(); | |
void add(string method); | |
void setName(); | |
void setPhone(); | |
void setCommentary(); | |
//void save(ofstream &F); | |
//void load(ifstream &F); | |
}; |
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"Menu.h" | |
void main() | |
{ | |
Menu*A=new Menu; | |
A->load(); | |
A->printCont(); | |
A->MainMenu(); | |
} |
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"note.h" | |
note::note(void) | |
{ | |
type=new char[4]; | |
type="note"; | |
Body=0; | |
Header=0; | |
}; | |
note::~note(void) | |
{ | |
if (type != 0) | |
delete type; | |
if(Body!=0) | |
delete Body; | |
if(Header!=0) | |
delete Header; | |
}; | |
char* note::Type() | |
{ | |
return type; | |
}; | |
void note::print() | |
{ | |
cout<<type<<endl; | |
if (Header != "\0") | |
cout << Header << endl; | |
else | |
cout << "Header is empty" << endl; | |
if(Body!="\0") | |
cout << Body << endl; | |
else | |
cout << "Body is empty" << endl; | |
} | |
void note::initBody(int a) | |
{ | |
if(Body!=0) | |
delete Body; | |
Body = new char[a]; | |
}; | |
void note::initHeader(int a) | |
{ | |
if(Header !=0) | |
delete Header; | |
Header = new char[a]; | |
}; | |
void note::setBody() | |
{ | |
char a[5000]; | |
cout << "Enter the note" << endl; | |
cin >> a; | |
initBody(strlen(a)+1); | |
strcpy(Body,a); | |
}; | |
void note::setHeader() | |
{ | |
char a[5000]; | |
cout << "Enter the header" << endl; | |
cin >> a; | |
initHeader(strlen(a)+1); | |
strcpy(Header,a); | |
}; | |
void note::add(string method) | |
{ | |
if (method != "new") | |
return; | |
cout << "Creating new note" << endl; | |
setHeader(); | |
setBody(); | |
}; | |
void note::edit() | |
{ | |
int i; | |
while(1) | |
{ | |
cout << "1 - edit header\n2 - edit note\n0 - exit" << endl; | |
cin >> i; | |
switch(i) | |
{ | |
case 1: | |
setHeader(); | |
break; | |
case 2: | |
setBody(); | |
break; | |
case 0: | |
return; | |
default: | |
cout << "404" << endl; | |
break; | |
} | |
} | |
}; | |
/*void note::Legacysave(ofstream& F) | |
{ | |
F<<"''"<<type<<"'': {"<<endl; | |
F<<"''Header'': "<<"''"<<Header<<"'',"<<endl; | |
F<<"''Body'': "<<"''"<<Body<<"''"<<endl; | |
F<<"}"<<endl; | |
};*/ | |
/*void note::Legacyload(ifstream& F) | |
{ | |
string S; | |
getline(F,S); | |
int i=S.find("''",0); | |
if(i!=-1) | |
{ | |
int j=S.find("''",i+1); | |
string Info=S.substr(i+2,j-i-2); | |
if(Info=="Header") | |
{ | |
string Info1=S.substr(j+6,S.length()-j-8); | |
initHeader(Info1.length()+1); | |
strcpy(Header,Info1.c_str()); | |
} | |
if(Info=="Body") | |
{ | |
string Info1=S.substr(j+6,S.length()-j-8); | |
initBody(Info1.length()+1); | |
strcpy(Body,Info1.c_str()); | |
} | |
} | |
};*/ |
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"Book.h" | |
class note: public Book | |
{ | |
public: | |
note(); | |
~note(); | |
char* type; | |
char* Type(); | |
char* Body; | |
char* Header; | |
void print(); | |
void edit(); | |
void add(string method); | |
void initBody(int a); | |
void initHeader(int a); | |
void setBody(); | |
void setHeader(); | |
//void save(ofstream &F); | |
//void load(ifstream &F); | |
}; |
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"phone.h" | |
phone::phone(void) | |
{ | |
Phone=0; | |
type=0; | |
Commentary=0; | |
}; | |
phone::~phone(void) | |
{ | |
if(Phone!=0) | |
delete Phone; | |
if(type!=0) | |
delete type; | |
if(Commentary!=0) | |
delete Commentary; | |
}; | |
void phone::print() | |
{ | |
cout << "Phone type: " << type << endl; | |
cout << "Phone number: " << Phone << endl; | |
cout << "Commetary: " << Commentary << endl; | |
}; | |
void phone::initPhone(int a) | |
{ | |
if (Phone != "\0") | |
delete Phone; | |
Phone = new char[a]; | |
}; | |
void phone::initType(int a) | |
{ | |
if (type != "\0") | |
delete type; | |
type = new char[a]; | |
}; | |
void phone::initCommentary(int a) | |
{ | |
if (Commentary != "\0") | |
delete Commentary; | |
Commentary = new char[a]; | |
}; | |
void phone::setPhone() | |
{ | |
char P[100]; | |
cout << "Enter the number" << endl; | |
cin >> P; | |
initPhone(strlen(P)+1); | |
strcpy(Phone,P); | |
}; | |
void phone::setCommentary() | |
{ | |
char P[100]; | |
cout << "Enter the commentary" << endl; | |
cin >> P; | |
initCommentary(strlen(P)+1); | |
strcpy(Commentary,P); | |
}; | |
void phone::setType() | |
{ | |
char P[100]; | |
cout << "Enter the type" << endl; | |
cin >> P; | |
initType(strlen(P) + 1); | |
strcpy(type, P); | |
}; | |
void phone::add(string method) | |
{ | |
if (method != "new") | |
return; | |
cout << "Creating new phone" << endl; | |
setPhone(); | |
setType(); | |
setCommentary(); | |
}; | |
char* phone::Type() | |
{ | |
return type; | |
}; | |
void phone::edit() | |
{ | |
print(); | |
int i; | |
while(1) | |
{ | |
cout<<"1 - edit number\n2 - edit type\n3 - edit commentary\n0 - exit"<<endl; | |
cin>>i; | |
switch(i) | |
{ | |
case 1: | |
setPhone(); | |
break; | |
case 2: | |
setType(); | |
break; | |
case 3: | |
setCommentary(); | |
break; | |
case 0: | |
return; | |
default: | |
cout<<"404"<<endl; | |
break; | |
} | |
} | |
}; | |
/*void phone::Legacysave(ofstream &F) | |
{ | |
F<<"''"<<type<<"'': {"<<endl; | |
F<<"''Phone'': "<<"''"<<Phone<<"''"<<endl; | |
F<<"''Commentary'': "<<Commentary<<endl; | |
F<<"}"; | |
};*/ |
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"Book.h" | |
class phone: public Book | |
{ | |
public: | |
phone(); | |
~phone(); | |
char* Type(); | |
char*type; | |
char*Phone; | |
char*Commentary; | |
void print(); | |
void edit(); | |
void initPhone(int n); | |
void initType(int n); | |
void initCommentary(int n); | |
void setPhone(); | |
void setType(); | |
void setCommentary(); | |
void add(string method); | |
//void save(ofstream &F); | |
//void load(ifstream &F); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment