U E D R , A S I H C RSS

손동일/Telephone Book

Describe /TelephoneBook here.

Coding ..

~cpp 
#include <iostream>
using namespace std;

class TelephoneBook
{
private:
	char tel_num[14];
	char name[20];
	char group[20];
	char memo[50];
	int count;				//    ( 한  1  )
	int mode;				// 항   
	int menu_num;			// menu   
	char compare[20];
	char compare2[14];
//	char *compare2;
//	char *compare3;
//	char *compare4;
//	char *compare5;

	char compare3[20];
	char compare4[20];
	char compare5[50];

public:

	TelephoneBook();
	~TelephoneBook();
	void show();			//   ?     ..
	void input();			//     .
	void save();			//   .
	void menu();
	void check();			//  택하
	void check_search();	// 
	int mnreturn();			// menu_num 
	void change();			//  
	void remove();			//  
};

~cpp 


~cpp 
#include <iostream>  
using namespace std;  
#include <fstream>  
#include "TelephoneBook.h"  
#include <cstring>  
 
ofstream fout;    
ifstream fin;   
  
const char *filename = "text.txt";  
const int base_save = 4;                        //    .  
  


TelephoneBook::TelephoneBook()
{  
//	compare2 = new char[14];
//	compare3 = new char[20];
//	compare4 = new char[20];
//	compare5 = new char[50];
	count = 0;
	menu_num = 0;
};  
  
TelephoneBook::~TelephoneBook()  
{
};  
  
void TelephoneBook::input()                     //     .  
{  

        cout << "호 : " ;
        cin >> tel_num;
        cout << " : ";  
        cin >> name;  
        cout << " : ";  
        cin >> group;  
        cout << " : ";  
        cin >> memo;  
        save();  
}  
  
void TelephoneBook::save()                      //   .  
{  
        fout.open(filename, ios::app);  
          
        fout << tel_num << endl;  
        fout << name << endl;  
        fout << group << endl;  
        fout << memo << endl;  
  
        count = count + 1;  
  
        fout.close();  
}  
  
  
void TelephoneBook::menu()  
{  
        cout << ">  (:1, :2, :3)" << endl;   
        cin >> menu_num;
        if(menu_num == 1)  
        {  
                input();  
        }  
        else if(menu_num == 2)  
        {  
                check();
// 확 
//				cout << " . " << endl;
//                show();  
        }
        else   
        {  
                exit(0);  
        }  
}  
  
void TelephoneBook::check_search()  
{  
		fin.open(filename);

/*
		if(check_num >= 1)		//  ..
		{
			cout << compare << endl;

			cout << compare2 << endl << compare3 << endl << compare4<<endl<<compare5<< endl;
		}
*/
	    for(int i=0; i<(base_save+count)*4; i++)
		{  
                fin.getline(compare2, 14, '\n');
                fin.getline(compare3, 20, '\n');  
                fin.getline(compare4, 20, '\n');  
                fin.getline(compare5, 50, '\n'); 
				
				if(mode == 1)
                {  
                        if(!strcmp(compare, compare2))                  //   0 .  
                        {  
                                show();
                        }  
                }  
                else if(mode == 2)  
                {  
                        if(!strcmp(compare, compare3))                  //   0 .  
                        {  
                                show();
//								check_num = check_num + 1;		//   
						// break  .. ㅡㅜ;;
						// compare    .. 

								break;
                        }  
                }  
                else if(mode == 3)  
                {  
                        if(!strcmp(compare, compare4))                  //   0 .  
                        {  
                                show();  
                        }  
                }  
        }
//		cout << "for  . " << endl;
		fin.close();
//		cout << compare2 << endl << compare3 << endl << compare4 << endl << compare5 << endl;
		
}  
  
void TelephoneBook::check()                     //  택하  
{    
        cout << "> 택 (호:1, :2, :3)" << endl;   
        cin >> mode;
  
        if(mode == 1)  
        {  
                cout << "호 : ";  
                cin >> compare;  
                  
                check_search();   					
        }  
        else if(mode == 2)  
        {  
                cout << " : ";  
                cin >> compare;
//				cout << compare;

                check_search();
        }  
        else if(mode == 3)  
        {  
                cout << " : ";  
                cin >> compare;  
  
                check_search();  
        }  

}  
  
void TelephoneBook::show()   
{  
    cout << "호 : " << compare2 << endl;   
    cout << " : " << compare3 << endl;   
    cout << " : " << compare4 << endl;   
    cout << " : " << compare5 << endl;   

}

void TelephoneBook::change()
{
	cout << "  ." <<endl;
//	cout << compare2 << endl << compare3 << endl << compare4 << endl << compare5 << endl;
//	fout.open(filename, ios::in | ios::out | ios::app );

//	strcpy(compare2, "             ");

//	fout.seekp(compare2);
//	fout << compare2;

}

void TelephoneBook::remove()
{
	cout << "  ." <<endl;

//	cout << compare2 << endl << compare3 << endl << compare4 << endl << compare5 << endl;

}

 
//  
//    통해     ㅡㅡ ㅋ;; 

int TelephoneBook::mnreturn()
{
	return menu_num;
}
 
 
int main()  
{  
//	TelephoneBook *a = new TelephoneBook();

	int ddd;

	TelephoneBook a;

	do
	{
		a.menu();
		if(a.mnreturn() == 2)
		{
			cout << "(:1, :2, :3) " << endl;
			cin >> ddd;
			if(ddd != 3)
				break;
		}
	}while(a.mnreturn() == 2);

	if(ddd == 1)
		a.change();
	if(ddd == 2)
		a.remove();
	
		cout << "." << endl;
 
        return 0;  
}  
 






Think about it..

~cpp 
6/4 토토토토토토

포    .. 

	compare2 = new char [4];

		cin >> compare;
//		int ok;
		fin.getline(compare2, 30, '\n');
//		fin >> compare2[0];
		cout << compare2;





Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:30:14
Processing time 0.0161 sec