私はC++の初心者です。私はMS visual 2010 expressを使用しています。 私はこの中に間違っているかを把握するように見えることはできません。 (長方形や正方形のいずれかのエリアを与える)これは何が問題なのですか?(C++)
#include<iostream>
using namespace std;
class RectClass{
public:
int l,b,area_rect;
void getDimensions_rect()
{
cout<<"Enter the length: "<<endl;
cin>>l;
cout<<"/n Enter the breadth: "<<endl;
cin>>b;
}
int givearea_rect(int l,int b)
{
area_rect=l*b;
return area_rect;
}
}
class SqrClass{
public:
int s1,s2,area_sqr;
void getDimensions_sqr()
{
cout<<"Enter the first side: "<<endl;
cin>>s1;
cout<<"/n Enter the second side: "<<endl;
cin>>s2;
}
int givearea_sqr(int s1, int s2)
{
area_sqr=s1*s2;
return area_sqr;
}
}
int main()
{
RectClass RectObj;
SqrClass SqrObj;
int reply1;
cout<<"What do you want to do?/n 1)Area of Rectangle./n 2)Area of Square"<<endl;
cin>>reply1;
if (reply1==1)
{
RectObj.getDimensions_rect();
RectObj.givearea_rect(RectObj.l,RectObj.b);
cout<<"The area is: "<<RectObj.area_rect;
}
else if (reply1==2)
{
SqrObj.getDimensions_sqr();
SqrObj.givearea_sqr(SqrObj.s1, SqrObj.s2);
cout<<"The area is: "<<SqrObj.area_sqr;
}
else
{
cout<<"Invalid command:Please try again"<<endl;
}
cin.get();
cin.get();
return 0;
}
私はこれを実行してみたが、それは常に(私から取ってチュートリアルを取っているエラーを示していニューボストン)。
1> ------ビルド開始:プロジェクト:TheNewBostonTestsを、構成: デバッグのWin32 ------
1> the_sourceFile.cpp
1> C:\ユーザー\ pc03 \ドキュメント\ビジュアルスタジオ 2010 \ projects \ thenewbostontests \ newewostostest \ the_sourcefile.cpp(24): エラーC2236:予期しない 'クラス' 'SqrClass'。あなたは ';'を忘れましたか?
1> C:プロジェクト\ Visual Studioの\ \ユーザー\ PC03の\ドキュメント 2010 \ thenewbostontests \ thenewbostontests \ the_sourcefile.cpp(24): エラーC2143:構文エラー:見つかりません ';'前に '{'
1> C: エラーC2447: '{':欠落している関数ヘッダ(旧プロジェクト\ thenewbostontests \ thenewbostontests \ the_sourcefile.cpp(24)\ Visual Studioの 2010 \ \ユーザー\ PC03の\ドキュメントスタイルの正式なリスト)
1> C:?プロジェクト\ Visual Studioの 2010 \ \ユーザー\ PC03の\ドキュメント\ thenewbostontests \ thenewbostontests \ the_sourcefile.cpp(46): エラーC2065: 'SqrClass':宣言されていない識別子
1> c:¥users¥pc03¥documents¥visual studio 2010 \ projects \ newewesting \ new_sourcefile.cpp(46): エラーC2146:構文エラー: ';'がありません。識別子の前に 'SqrObj'
1> C: エラーC2065: 'SqrObj':宣言されていない識別子
プロジェクト\ thenewbostontests \ thenewbostontests \ the_sourcefile.cpp(46)\ Visual Studioの 2010 \ \ユーザー\ PC03の\ドキュメント1> C:プロジェクト\ Visual Studioの 2010 \ \ユーザー\ PC03の\ドキュメント\ thenewbostontests \ thenewbostontests \ the_sourcefile.cpp(58): エラーC2065: 'SqrObj':宣言されていない識別子
1> C:\ユーザー\ pc03 \ documents \ visualスタジオ 2010年\ projects \ newewithstest \ \ new_sourcefile.cpp(58): エラーC2228:Visual Studioの \ \ユーザー\ PC03の\ドキュメント: '.getDimensions_sqr' の左側にはタイプが '' unknown型 ''
1> Cである>クラス/構造体/共用
1を持っている必要があります2010年のプロジェクト\ \ thenewbostontests \ thenewbostontests \ the_sourcefile.cpp(59): エラーC2065: 'SqrObj':宣言されていない識別子
1> C:プロジェクト\ \ Visual Studioの\ユーザー\ PC03の\ドキュメント 2010 \ thenewbostontests \ thenewbostontests \ the_sourcefile.cpp(59): エラーC2228:左の '。プロジェクト\ Visual Studioの 2010 \ \ユーザー\ PC03の\ドキュメント\ thenewbostontests \ thenewbostontests \:givearea_sqrは '不明型 ''
1> C」タイプがある>クラス/構造体/共用
1を持っている必要があります' the_sourcefile.cpp(59): エラーC2065: 'SqrObj':宣言されていない識別子
1> C:プロジェクト\ Visual Studioの\ \ユーザー\ PC03の\ドキュメント 2010 \ thenewbostontests \ thenewbostontests \ the_sourcefile.cpp(59): エラーC2228: '.s1'の左側にはクラス/構造体/共用体が必要です
1>タイプは '' unknown型 ''
1>はc:プロジェクト\ Visual Studioの\ \ユーザー\ PC03の\ドキュメント 2010 \ thenewbostontests \ thenewbostontests \ the_sourcefile.cpp(59): エラーC2065:「 SqrObj ':宣言されていない識別子
1> C:プロジェクト\ Visual Studioの\ \ユーザー\ PC03の\ドキュメント 2010 \ thenewbostontests \ thenewbostontests \ the_sourcefile.cpp(59): エラーC2228:の左' .s2' が持っている必要がありますクラス/構造体/共用体
1>型は「unknown-type」です
1> C:プロジェクト\ Visual Studioの 2010 \ \ユーザー\ PC03の\ドキュメント\ thenewbostontests \ thenewbostontests \ the_sourcefile.cpp(60): エラーC2065: 'SqrObj':宣言されていない識別子
1> C:\ユーザー\ PC03の\ドキュメントをVisual Studioの 2010 \プロジェクト\ \ thenewbostontests \ thenewbostontests \ the_sourcefile.cpp(60): エラーC2228: '.area_sqr' の左はタイプが '' された>
1クラス/構造体/共用体を持っている必要があります
==========ビルド:0成功、1失敗、0最新、0スキップ==========
クラスのために ';'最後に '}'を追加します – marcinj
"> ... the_sourcefile.cpp(24):エラーC2236:予期しない 'class' 'あなたは ';'を忘れましたか? " 24行目に ';'がありません – user1708860
コンパイラはあなたに "あなたを忘れましたか?"と尋ねます。まあ、どこかセミコロンを忘れましたか? –