Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <cstring>
- enum Extension{txt, pdf, exe};
- using namespace std;
- class File{
- private:
- char *ime;
- Extension ekstenzija;
- char *sopstvenik;
- int golemina;
- public:
- File(){
- ime=NULL;
- sopstvenik=NULL;
- ekstenzija=Extension (0);
- golemina=0;
- }
- File(char *ime, char *sopstvenik, int golemina, Extension ekstenzija){
- this->ekstenzija=ekstenzija;
- this->golemina=golemina;
- this->ime=new char[strlen(ime)+1];
- strcpy(this->ime, ime);
- this->sopstvenik=new char[strlen(sopstvenik)+1];
- strcpy(this->sopstvenik, sopstvenik);
- }
- File(const File &f){
- this->ekstenzija=f.ekstenzija;
- this->golemina=f.golemina;
- this->ime=new char[strlen(f.ime)+1];
- strcpy(this->ime, f.ime);
- this->sopstvenik=new char[strlen(f.sopstvenik)+1];
- strcpy(this->sopstvenik, f.sopstvenik);
- }
- File &operator=(const File &f){
- if(this!=&f) {
- this->ekstenzija = f.ekstenzija;
- this->golemina = f.golemina;
- delete [] ime;
- this->ime = new char[strlen(f.ime) + 1];
- strcpy(this->ime, f.ime);
- delete [] sopstvenik;
- this->sopstvenik = new char[strlen(f.sopstvenik) + 1];
- strcpy(this->sopstvenik, f.sopstvenik);
- }
- return *this;
- }
- ~File(){
- delete ime;
- delete sopstvenik;
- }
- void print(){
- cout<<"File name: "<<ime<<".";
- if(ekstenzija==0) cout<<"pdf"<<endl;
- if(ekstenzija==1) cout<<"txt"<<endl;
- if(ekstenzija==2) cout<<"exe"<<endl;
- cout<<"File owner: "<<sopstvenik<<endl;
- cout<<"File size: "<<golemina<<endl;
- }
- bool equals(const File & that){
- if((!strcmp(that.ime, ime))&&(!strcmp(sopstvenik, that.sopstvenik))&&(that.ekstenzija==ekstenzija)){
- return true;
- }
- else return false;
- }
- bool equalsType(const File & that){
- if((!strcmp(that.ime, ime)) && (that.ekstenzija==ekstenzija)){
- return true;
- }
- else return false;
- }
- };
- class Folder{
- private:
- char *ime;
- int n;
- File *fajlovi;
- public:
- Folder(){
- fajlovi=NULL;
- n=0;
- }
- Folder(const char *ime){
- this->ime=new char[strlen(ime)+1];
- strcpy(this->ime, ime);
- fajlovi=NULL;
- n=0;
- }
- Folder(const Folder &f){
- this->ime=new char[strlen(f.ime)+1];
- strcpy(this->ime, f.ime);
- this->n=f.n;
- this->fajlovi=new File[n];
- for(int i=0; i<n; i++){
- fajlovi[i]=f.fajlovi[i];
- }
- }
- Folder &operator=(const Folder &f){
- if(this!=&f) {
- delete [] ime;
- delete [] fajlovi;
- this->ime = new char[strlen(f.ime) + 1];
- strcpy(this->ime, f.ime);
- this->n = f.n;
- this->fajlovi = new File[n];
- for (int i = 0; i < n; i++) {
- fajlovi[i] = f.fajlovi[i];
- }
- }
- return *this;
- }
- ~Folder(){
- delete [] fajlovi;
- delete [] ime;
- }
- void print(){
- cout<<"Folder name: results"<<endl;
- for(int i=0; i<n; i++){
- fajlovi[i].print();
- }
- }
- void remove(const File & file){
- int razlicni=0;
- for(int i=0; i<n; i++){
- if(fajlovi[i].equals(file)==false){
- razlicni++;
- }
- }
- File *tmp=new File[razlicni];
- int j=0;
- for(int i=0; i<n; i++){
- if(fajlovi[i].equals(file)==false){
- tmp[j]=fajlovi[i];
- j++;
- }
- }
- delete [] fajlovi;
- fajlovi=tmp;
- n=razlicni;
- }
- void add(const File & file){
- File *tmp=new File[n+1];
- for(int i=0; i<n; i++){
- tmp[i]=fajlovi[i];
- }
- tmp[n]=file;
- n++;
- delete [] fajlovi;
- fajlovi=tmp;
- }
- };
- int main() {
- char fileName[20];
- char fileOwner[20];
- int ext;
- int fileSize;
- int testCase;
- cin >> testCase;
- if (testCase == 1) {
- cout << "======= FILE CONSTRUCTORS AND = OPERATOR =======" << endl;
- cin >> fileName;
- cin >> fileOwner;
- cin >> fileSize;
- cin >> ext;
- File created = File(fileName, fileOwner, fileSize, (Extension) ext);
- File copied = File(created);
- File assigned = created;
- cout << "======= CREATED =======" << endl;
- created.print();
- cout << endl;
- cout << "======= COPIED =======" << endl;
- copied.print();
- cout << endl;
- cout << "======= ASSIGNED =======" << endl;
- assigned.print();
- }
- else if (testCase == 2) {
- cout << "======= FILE EQUALS & EQUALS TYPE =======" << endl;
- cin >> fileName;
- cin >> fileOwner;
- cin >> fileSize;
- cin >> ext;
- File first(fileName, fileOwner, fileSize, (Extension) ext);
- first.print();
- cin >> fileName;
- cin >> fileOwner;
- cin >> fileSize;
- cin >> ext;
- File second(fileName, fileOwner, fileSize, (Extension) ext);
- second.print();
- cin >> fileName;
- cin >> fileOwner;
- cin >> fileSize;
- cin >> ext;
- File third(fileName, fileOwner, fileSize, (Extension) ext);
- third.print();
- bool equals = first.equals(second);
- cout << "FIRST EQUALS SECOND: ";
- if (equals)
- cout << "TRUE" << endl;
- else
- cout << "FALSE" << endl;
- equals = first.equals(third);
- cout << "FIRST EQUALS THIRD: ";
- if (equals)
- cout << "TRUE" << endl;
- else
- cout << "FALSE" << endl;
- bool equalsType = first.equalsType(second);
- cout << "FIRST EQUALS TYPE SECOND: ";
- if (equalsType)
- cout << "TRUE" << endl;
- else
- cout << "FALSE" << endl;
- equalsType = second.equals(third);
- cout << "SECOND EQUALS TYPE THIRD: ";
- if (equalsType)
- cout << "TRUE" << endl;
- else
- cout << "FALSE" << endl;
- }
- else if (testCase == 3) {
- cout << "======= FOLDER CONSTRUCTOR =======" << endl;
- cin >> fileName;
- Folder folder(fileName);
- folder.print();
- }
- else if (testCase == 4) {
- cout << "======= ADD FILE IN FOLDER =======" << endl;
- char name[20];
- cin >> name;
- Folder folder(name);
- int iter;
- cin >> iter;
- while (iter > 0) {
- cin >> fileName;
- cin >> fileOwner;
- cin >> fileSize;
- cin >> ext;
- File file(fileName, fileOwner, fileSize, (Extension) ext);
- folder.add(file);
- iter--;
- }
- folder.print();
- }
- else {
- cout << "======= REMOVE FILE FROM FOLDER =======" << endl;
- char name[20];
- cin >> name;
- Folder folder(name);
- int iter;
- cin >> iter;
- while (iter > 0) {
- cin >> fileName;
- cin >> fileOwner;
- cin >> fileSize;
- cin >> ext;
- File file(fileName, fileOwner, fileSize, (Extension) ext);
- folder.add(file);
- iter--;
- }
- cin >> fileName;
- cin >> fileOwner;
- cin >> fileSize;
- cin >> ext;
- File file(fileName, fileOwner, fileSize, (Extension) ext);
- folder.remove(file);
- folder.print();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement