c++질문이요.

이상호@Google의 이미지

이제 막 c++ 공부하는 사람입니다.
강의를 들으면서 그대로 적었는데 오류가 나서 질문올립니다 ㅠㅠ

강의 내용은 이렇습니다.
#include
using namespace std;

class Sungjuk {
private:
int no;
char name[20];
int cpp, java, jsp, total;
double average;
public:
Sungjuk() {
cout << "기본 생성자가 실행됩니다." << endl;
}
Sungjuk (int no, char name[20], int cpp, int java, int jsp) {
this->no = no;
strcpy_s(this->name, name);
this->cpp = cpp;
this->java = java;
this->jsp = jsp;
total = cpp + java + jsp;
average = (double)total / 3;
}

void toString() {
cout << no << ". " << name << "님의 평균 점수는" << average << "점 입니다." << endl;
}
};

void main() {

class Sungjuk sungjuk1;
sungjuk1.toString();
class Sungjuk sungjuk2(1, "홍길동", 100, 100, 99);
sungjuk2.toString();
}

강의 선생님이 쓰신 코드 그대로 썻는데 선생님은 실행이 되고 전 오류가 뜹니다.

1>------ 빌드 시작: 프로젝트: 02day, 구성: Debug Win32 ------

sample1.cpp(40,13): warning C4326: 'main'의 반환 형식이 'int'이어야 하는데 'void'입니다.
sample1.cpp(46,57): error C2664: 'Sungjuk::Sungjuk(Sungjuk &&)': 인수 2을(를) 'const char [7]'에서 'char []'(으)로 변환할 수 없습니다.
sample1.cpp(46,31): message : 문자열 리터럴로부터의 변환은 const 한정자가 손실됩니다(/Zc:strictStrings 참조).
sample1.cpp(21,5): message : 'Sungjuk::Sungjuk' 선언을 참조하십시오.
1>"02day.vcxproj" 프로젝트를 빌드했습니다. - 실패
========== 빌드: 성공 0, 실패 1, 최신 0, 생략 0 ==========

오류 내용을 이렇게 뜨네요... 프로그램은 비쥬얼 스튜디오 쓰고있습니다. 설정이 안돼있어서 안돼는건가 싶기도한데... 어떻게 고치면 실행이 될까요?
const라는 건 안넣은데 왜 저리 뜨는건지.

마지막의 class Sungjuk sungjuk2(1, "홍길동", 100, 100, 99);
sungjuk2.toString();
부분을 주석처리하고 실행하면 잘 실행되는데 주석을 풀면 1 밑에 빨간 밑줄 쳐지면서 오류뜨네요.

File attachments: 
첨부파일 크기
Image icon day2.png54.37 KB
gkgkghgh의 이미지

I recommend to not follow the lecture. The example simply sucks. Buy a good C++ text and study with it. You know what? The lecturer is just a loser!

sddddd의 이미지

> The lecturer is just a loser!

Most of lecturers are just a loser! :) haha,,

ifree의 이미지

Does that mean winners are not teaching?
What are they doing?

익명 사용자의 이미지

컴파일이 안 되는 게 정상입니다.
조금만 고치면 컴파일이 되게 만들 수 있긴 합니다만, 그게 문제가 아니로군요.

진짜 문제는 이런 낮은 퀄리티의 예제 코드를 제시하는 강의를 귀하께서 듣고 계신다는 겁니다.
코드 하나 고쳐 드려 봤자 밑 빠진 독에 물 붓는 격이죠.

아직 늦지 않은 것 같으니 다른 강의로 갈아타시는 게 좋겠습니다.

익명 사용자의 이미지

리눅스에서는 아래처럼 하면 됩니다.

#include <iostream>
#include <cstring>
using namespace std;
 
class Sungjuk {
private:
    int no;
    char name[20];
    int cpp, java, jsp, total;
    double average;
public:
    Sungjuk() {
        cout << "기본 생성자가 실행됩니다." << endl;
    }
    Sungjuk (int no, const char *name, int cpp, int java, int jsp) {
        this->no = no;
        strcpy(this->name, name);
        this->cpp = cpp;
        this->java = java;
        this->jsp = jsp;
        total = cpp + java + jsp;
        average = (double)total / 3;
    }
 
    void toString() {
        cout << no << ". " << name << "님의 평균 점수는" << average << "점 입니다." << endl;
    }
 
};
 
int main() {
    class Sungjuk sungjuk1(1, "김말동", 50, 60, 70);
    sungjuk1.toString();
    class Sungjuk sungjuk2(2, "홍길동", 100, 100, 99);
    sungjuk2.toString();
}
 
------------------------------------------------------
 
1. 김말동님의 평균 점수는60점 입니다.
2. 홍길동님의 평균 점수는99.6667점 입니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.