2020-11-30 고급프로그래밍

Hyeonu_Chun·2021년 6월 22일
0

Absolute C++ 6th ed./Savitch Chap.11 Programming Project.4

  1. 문제 기술
    필자는 본문에 있는 관리자와 유저의 로그인 정보를 관리하는 시스템의 구현을 요한다.

  2. 설계 계획
    본문에 따라 각각의 클래스를 만들어 해당하는 멤버함수를 구현하고, 유저와 관리자에 해당하는 아이디와 비밀번호를 입력하였을 때 작동하는 메인을 설계한다.

  3. 데이터 처리 과정
    본문에 있는 Security헤더를 각각 User와 Administrator 헤더에 선언하여 Security.cpp에 선언한다. 이후 Security 클래스의 멤버함수에서 나온 리턴값에 따라 각각의 클래스의 Login 함수의 아규먼트로 입력하여 나온 결과값에 따라 로그인을 시킨다.

  4. 실행 결과 및 분석

<Security.h>

#pragma once
#include <iostream>
#include <string>
using namespace std;

class Security {
public:
	static int validate(string username, string password);
};

int Security::validate(string username, string password) {
	if ((username == "abbott") && (password == "monday")) return 1;
	if ((username == "costello") && (password == "tuesday")) return 2;
	return 0;
}

<Administrator.h>

#pragma once
#include "Security.h"

class Administrator {
public:
	bool Login(int num);
};

bool Administrator::Login(int num) {
	if (num == 2) return true;
	else return false;
}

<User.h>

#pragma once
#include "Security.h"

class User {
public:
	bool Login(int num);
};

bool User::Login(int num) {
	if (num == 1) return true;
	else return false;
}

<Security.cpp>

#include "Administrator.h"
#include "User.h"

int main() {
	Security a;
	Administrator b;
	User c;
	
	if (c.Login(a.validate("abbott", "monday")) == 1) cout << "Good morning, user" << endl;
	if (b.Login(a.validate("costello", "tuesday")) == 1) cout << "Good morning, admin" << endl;
	return 0;
}

profile
Stay hungry, stay foolish

0개의 댓글