Я новичок в 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;
}
Стараюсь работает это, но это всегда показывает ошибки (я беру принимая уроки из TheNewBoston).
1> ------ Сложение начал: Project: TheNewBostonTests, Конфигурация: Debug Win32 ------
1> the_sourceFile.cpp
1> C: \ users \ pc03 \ documents \ visual studio 2010 \ projects \ thenewbostontests \ thenewbostontests \ the_sourcefile.cpp (24): ошибка C2236: неожиданный 'класс' 'SqrClass'. Вы забыли «?»?
1> C: \ Users \ PC03 \ документы \ Visual Studio 2010 \ проекты \ thenewbostontests \ thenewbostontests \ the_sourcefile.cpp (24): ошибка C2143: синтаксическая ошибка: отсутствует ';' до того '{'
1> C: \ Users \ PC03 \ документы \ Visual Studio 2010 \ проекты \ thenewbostontests \ thenewbostontests \ the_sourcefile.cpp (24): ошибка C2447: '{': отсутствует заголовок функции (старый -стиль формальный список)
1> с: \ Пользователи \ PC03 \ документы \ Visual Studio 2010 \ проекты \ thenewbostontests \ thenewbostontests \ the_sourcefile.cpp (46): ошибка C2065: 'SqrClass': необъявленный идентификатор
1> c: \ users \ pc03 \ documents \ visual studio 2010 \ projects \ thenewbostontests \ thenewbostontests \ the_sourcefile.cpp (46): ошибка C2146: синтаксическая ошибка: отсутствует ';' Перед идентификатором 'SqrObj'
1> C: \ Users \ PC03 \ документы \ Visual Studio 2010 \ проекты \ thenewbostontests \ thenewbostontests \ the_sourcefile.cpp (46): ошибка C2065: 'SqrObj': необъявленный идентификатор
1> C: \ Users \ PC03 \ документы \ Visual Studio 2010 \ проекты \ thenewbostontests \ thenewbostontests \ the_sourcefile.cpp (58): ошибка C2065: 'SqrObj': необъявленный идентификатор
1> C: \ users \ pc03 \ documents \ visual studio 2010 \ projects \ thenewbostontests \ thenewbostontests \ the_sourcefile.cpp (58): ошибка C2228: слева от '.getDimensions_sqr' должны иметь класс/структуры/объединение
1> типа '' неизвестного типа ''
1> C: \ Users \ PC03 \ документы \ Visual Studio 2010 \ Projects \ thenewbostontests \ thenewbostontests \ the_sourcefile.cpp (59): ошибка C2065: 'SqrObj': необъявленный идентификатор
1> C: \ Users \ PC03 \ документы \ Visual Studio 2010 \ проекты \ thenewbostontests \ thenewbostontests \ the_sourcefile.cpp (59): ошибка C2228: слева от '.givearea_sqr»должен иметь класс/структуры/объединения
1> тип '' неизвестный тип ''
1> C: \ Users \ PC03 \ документы \ Visual Studio 2010 \ проекты \ thenewbostontests \ thenewbostontests \ the_sourcefile.cpp (59): ошибка C2065: 'SqrObj': необъявленный идентификатор
1> C: \ Users \ PC03 \ документы \ Visual Studio 2010 \ проекты \ thenewbostontests \ thenewbostontests \ the_sourcefile.cpp (59): ошибка C2228: слева от '.s1' должно быть класс/структура/соединение
1> тип '' неизвестный тип ''
1> C: \ Users \ PC03 \ документы \ Visual Studio 2010 \ проекты \ thenewbostontests \ thenewbostontests \ the_sourcefile.cpp (59): ошибка C2065: ' SqrObj ': необъявленный идентификатор
1> C: \ Users \ PC03 \ документы \ Visual Studio 2010 \ проекты \ thenewbostontests \ thenewbostontests \ the_sourcefile.cpp (59): ошибка C2228: слева от' .s2' должен иметь класс/структура/объединение
1> тип '' неизвестный тип ''
1> C: \ Users \ PC03 \ документы \ Visual Studio 2010 \ проекты \ thenewbostontests \ thenewbostontests \ the_sourcefile.cpp (60): ошибка C2065: 'SqrObj': необъявленный идентификатор
1> C: \ Users \ PC03 \ документы \ визуальной студии 2010 \ Projects \ thenewbostontests \ thenewbostontests \ the_sourcefile.cpp (60): ошибка C2228: слева от '.area_sqr' должен иметь класс/структуры/объединения
1> тип '' неизвестный тип ''
========== Сложение: 0 удалось, 1 не удалось, 0 уточненный, 0 пропущено ==========
add ';' after last '}' для класса – marcinj
Он точно описывает, что некоторые из ошибок, например: "> ... the_sourcefile.cpp (24): ошибка C2236: неожиданный 'класс' ' SqrClass '. Вы забыли «?»? В строке 24 вам не хватает ';' – user1708860
. Компилятор спрашивает вас: «Вы забыли«; »?». Ну, ты где-то забыл точку с запятой? –