A simple file management program

zhaozj2021-02-16  47

Node.h

=====================================

#include template class node {private: Node * next; public: t data; node (void); Node (t data1, node * p = null); void insertafter Node * P); void deleteafter (void); Node * NextNode (void);}; template node :: node (void) {Next = null;} template Node :: Node (t data1, node * p) {data = data1; next = p;} template void node :: insertafter (Node * P ) {P-> next = next; next = p;} template void node :: deleteafter (void) {node * temp; temp = next; Next = Temp-> Next; Delete Temp;} template node * node :: nextnode (void) {return next;}

List.h

=====================================

#include #include #include "node.h" template class list {private: Node * head, * NewNode, * Last, * currnode, * Prenode; public: List (void); Node * setNode (t data2, node * p = null); Void Createlist (t data2, node * p = null); Void Insertlast (T P); void deletedata (T d); void print (void); void athead (void); t data (void); Node * Next (void); Node * currnode (void);} Template List :: List (void) {head = null; new = null; las = null; currnode = null; prenode = null;} template node * List < T> :: setNode (t data2, node * p) {newnode = new node (data2); return newnode;} template void list :: Createlist (t data2, node * p = null) {newNode = new node (data2); if (head == null) {head = newNode;} else {currnode = head; while (currnode-> nextnode ()! = Null ) {Currnode = currnode-> NextNode ();} currnode-> i NSERTAFTER (newNode); currnode = newNode;} last = newnode;} template void list :: INSERTLAST (TP) {newNode = new node (p); if (Last-> NextNode () == null) {Last-> INSERTAFTER (NEWNODE);} else {cout << "there {cout <<"} endl; exit (0);}} template void list :: DeleteData (T D) {if (Head == Null) {COUT << "NO DATA IN THE LIST" << Endl; Exit (0);

} If (Head-> Data == D) {head = head-> nextnode ();} else {currnode = head; while (currnode! = Null) {if (currnode-> data! = D) {Prenode = currnode Currnode = currnode-> NextNode ();} else {prenode-> deleteafter (); currnode = prenode-> NextNode ();}}}} template void list :: print (void) { Currnode = head; if (head == null) {cout << "no data in list" << end1; exit (0);} while (currnode! = null) {cout << currnode-> data << " CURRNODE = currnode-> NextNode ();} cout << Endl;} template void list :: deletelist (void) {node * temp; if (head == null) {cout << "no data in list" << Endl; exit (0);} while (head! = null) {temp = head; Head = head-> nextnode (); delete temp;}} template void List :: athead (void) {if (head! = null) {currnode = head;} ​​else {cout << "no data at head" << END l; exit (0);}} template t list :: data (void) {if (currnode! = null) {return currnode-> data;}}} template node * list :: next (void) {if (currnode! = null) {currnode = currnode-> NextNode (); return currnode;} else {return null;}} template node * List :: currnode (void) {return currnode;} guanli.cpp

==============================================

#include #include #include #include "list.h" struct file // file struct; {string filename; string aboutfile; string filepath;}; struct getfile {string filename; string aboutfile; String filepath;}; void main (void) {Int select; file myfile; String space, FindValue; OfStream Writefile; list mylist; char ch, text; int stringsize, i; ;;) {String lineValue; // jing zhi zai for (;;) {} xuan huan zhong ding yi (1-3); string openname ("/ home / c / zuoping2 / jiru"); // 2 ifstream readfile (OpenName.c_STR (), ios :: in); // 3 string :: size_type pos = 0, pre = 0; getfile getmyfile; cout << "1: add file" << endl; cout << "2: find file << end1 COUT << "3: watch file << endl; cout <<" 4: delete file "<< endl; cout <<" 5: quite "<< Endl; cin >> select; switch (select) {cas 1 : Writefile.open ("/ Home / C / Zuoping2 / Jiru", iOS :: out | os :: app); if (! Writefile ) {COUT << "DON't Open Jiru file" << endl; exit (1);} getLine (cin, space, '/ n'); cout << "please input file name" << Endl; getLine CIN, MyFile.FileName, '/ n'); cout << "please input file description" << Endl; getLine (cin, myfile.aboutfile, '/ n'); cout << "please input file path" << Endl; getLine (cin, myfile.filepath, '/ n'); if (myfile.filepath [myfile.filepath.size () - 1] == '/'

) {Writefile << ";" << myfile.aboutfile << ";" << myfile.filepath << ";" << '/ n';} else {myfile.filepath = myfile.filepath "/"; Writefile << myfile.filename << ";" << myfile.aboutfile << ";" << myfile.filepath << ";" << '/ n';} Writefile.close (); Break Case 2: if (! Readfile) {cout << "DON't open jiru file" << Endl; exit (-1);} cout << "please input file name for fir finding file << Endl; cin> > FindValue; WHILE (a "/ n ')) {pre = 0; POS = 0; // get file name; pOS = linevalue.find_first_of ('; ', pOS); getmyFile.FileName = lineValue . Substr (pre, pos-pre); POS; pre = POS; // get file description; pOS = lineValue.find_first_of (';', pOS); getmyfile.aboutfile = linevalue.substr (pre, POS-Pre, POS-Pre, POS; pre = POS; // Get File path; pOS = linevalue.find_first_of (';', pOS); getMYFILE.FILEPATH = lineValue.substr (pre, pos-pre); POS; pre = pos; // Get getMylist Data For Create List Mylist.createlist (getmyfile);} mylist.athead (); while (MyList.CurrNode ()! = Null) {if (myList.data (). FileName == FindValue) // when Find file;

{COUT << "Find file" << Endl; cout << "################################################# ######### << Endl; cout << "<" << mylist.data (). Aboutfile << "<" << Endl; cout << "######## ########################### "<< endl; cout <<" do you want to like Source "<< endl; cin >> CH; if (ch == 'y') {string filepath; filepath = mylist.data (). FilePath mylist.data (). FileName; // Erase Char '/ n'; For (i = 0; i <= filepath.size (); i ) {if (filepath [i] == '/ n') {filepath.rase (i, 1);}} // open file; ifstream OpenFiles OpenFiles.open (filepath.c_str (), iOS :: in); if (! OpenFiles) {CERR << "DON't Open file" << Endl; exit (-1);} // read file context; While (! OpenFiles.eof ()) {OpenFiles.get (Text); Cout.put (text);}}} mylist.next ();} mylist.deletelist (); break; case 3: if (! readfile) {cerr << "don't open the file << endl; exit (-1);} while (getfile (readfile, letvalue, '/ n')) {// get file name; pOS =

Linevalue.find_first_of (';', pOS); getMYFILE.FILENAME = lineValue.substr (pre, pos-pre); POS; pre = pos; // get file description; pOS = linevalue.find_first_of (';', POS); getMYFILE.ABOUTFILE = lineValue.substr (pre, POS-pre); POS; pre = pos; // get file path; pOS = linevalue.find_first_of (';', pos); getmyfile.filepath = lineValue .SUBSTR (Pre, POS-PRE); POS; pre = POS; // Get getMylist Data for Create List; mylist.createlist (getmyfile); POS = 0; pre = 0;} mylist.athead (); while ()! = null) {string filepath, descp; cout << "The file description" << endl; cout << mylist.data (). Aboutfile << Endl; cout << "**** *********************************************************** *********** "<< endl; cout <<" do you want to look Source "<< Endl; CIN >> CH; if (ch == 'y') { FilePath = mylist.data (). Filepath mylist.data (). FileName; POS = 0; for (i = 0; i <= filepath.size (); i ) {ix (filepath [i] == '/ n ') {filepath.rase (i, 1);}} cout << filepath; cout << endl; ifstream OpenFiles; OpenFiles.Open (filepath.c_str (), ios :: in); if (! OpenFiles) { CERR << "DON '

T open file "<< endl; exit (-1);} while (! OpenFiles.eof ()) {OpenFiles.get (text); cout.put (text);}} else if (ch == 'q" ) {Break;} mylist.next ();} mylist.deletelist (); break; case 5: exit (0);}}} Makefile ================== =======================================

Guanli: guanli.o list.h node.h g -g -i / home / c / zuoping2 / guanli.cpp -o guanli all: guanli.phony: Cleanclean: RM guanli.o

转载请注明原文地址:https://www.9cbs.com/read-26970.html

New Post(0)