게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
c++ 과제좀 도와주세요~!!!
게시물ID : programmer_13394짧은주소 복사하기
작성자 : 안녕하세
추천 : 0
조회수 : 568회
댓글수 : 9개
등록시간 : 2015/09/18 22:30:16
옵션
  • 본인삭제금지
class를 이용해서 월급을 입력받아서 월급을 구하는 코딩이 과제입니다 ㅠㅠ
class 내용을 짜보고 메인함수에 되나 안되나 적용을 해봤는데요
클래스 생성자 부분인
Employee()
 {
  setfirst_name();
  setlast_name();
  setsalary();
 }
이 부분 때문에 이상한 결과값이 나오는거 같은데 왜 그러는지 알려주세요 ㅠㅠㅠㅠ
 
 
#include <iostream>
using std::cout;
using std::endl;
using std::cin;
#include <string>
using std::string;
using std::getline;
class Employee
{
private:
 string first_name;
 string last_name;
 int salary;
public:
 Employee()
 {
  setfirst_name();
  setlast_name();
  setsalary();
 }
 void setfirst_name()
 {
  getline(cin, first_name);
 }
 void getfirst_name()
 {
  cout << first_name;
 }
 void setlast_name()
 {
  getline(cin, last_name);
 }
 void getlast_name()
 {
  cout << last_name;
 }
 void setsalary()
 {
  cin >> salary;
  if (salary < 0)
  {
   cout << "Error : Initial salary cannot be negative" << endl;
   salary = 0;
  }
 }
 void getsalary()
 {
  cout << salary;
 }
};
void main()
{
 Employee Employee1, Employee2;
 Employee1.setfirst_name();
 Employee1.getfirst_name();
}
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호