Chủ đề: Sửa lỗi giúp mình với
-
28-07-2014, 02:56 PM #1
Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Sửa lỗi giúp mình với
Đề bài tập là Xây dựng lớp na trận
Code bài tập nó như thế này
Mã:#include <iostream.h> #include <cstdlib> #include <stdio.h> #include <conio.h> using namespace std; class matran { private: int m,n; float ptu[10][10]; public: matran() { } matran(int x, int y) { m = x; n = y; } void nhapMT { for(int i=0;i<m;i++) for(int j=0;j<m;j++) { cout<<"phan tu["<<i<<","<<j<<"]="; cin>>ptu[i][j]; } } void xuatMT { for(int i=0;i<m;i++) { cout<<endl; for(int j=0;j<n;j++) cout<<ptu[i][j]<<"..."; } }; int matranDV() { for(int i=0;i<m;i++) for(int j=0;j<m;j++) { if((i==j)&&(ptu[i][j]!=1)) return 0; if((i!=j)&&(ptu[i][j]!=0)) return 0; } return 1; } } void main() { matran M(3,3); M.nhapMT(); M.xuatMT(); if(MT.matranDV()==1) cout<<"Ma tran don vi!"<<endl; else cout<<"Khong phai ma tran don vi!"<<endl; getch(); }
Mã:[Error] C:\Users\PC\Documents\C-Free\Temp\Untitled1.cpp:21: error: invalid member function declaration [Error] C:\Users\PC\Documents\C-Free\Temp\Untitled1.cpp:30: error: invalid member function declaration [Error] C:\Users\PC\Documents\C-Free\Temp\Untitled1.cpp:52: error: new types may not be defined in a return type [Error] C:\Users\PC\Documents\C-Free\Temp\Untitled1.cpp:52: error: two or more data types in declaration of `main' [Error] C:\Users\PC\Documents\C-Free\Temp\Untitled1.cpp:52: error: `main' must return `int' [Error] C:\Users\PC\Documents\C-Free\Temp\Untitled1.cpp:54: error: 'class matran' has no member named 'nhapMT' [Error] C:\Users\PC\Documents\C-Free\Temp\Untitled1.cpp:55: error: 'class matran' has no member named 'xuatMT' [Error] C:\Users\PC\Documents\C-Free\Temp\Untitled1.cpp:56: error: `MT' was not declared in this scope
Giúp mình,cảm ơn mọi người nhiềuView more random threads:
- cho em hỏi ve sắp xếp một dòng tăng dần trong ma trận th61 nào hả mấy pro
- bài tập c++
- Đề thi lý thuyết C FPT- Aptech. Ai có cho mình xin với
- Dùng lệnh gets để đọc xâu có cả kí tự cách trống nhưng chương trình bị lỗi, mình chưa rõ.
- Các vấn đề Liên quan đến Thuật Toán QHD
- Cần sự giúp đỡ về lập trình C/C++
- Con trỏ far (far pointer)
- Thứ 6 ngày 13
- Bị lỗi về bài toán tìm vị trí
- Sắp xếp các từ theo thứ tự trong từ điển
-
28-07-2014, 04:54 PM #2
Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Bạn sửa chỗ hàm xuatMT nhapMT phải thêm () nữa.
trong hàm main có biến MT chưa được khai báo.
Sau khi định nghĩa class phải có dấu ;
tùy chương trình mà bạn dùng để lập trình thì chỗ hàm mai phải là void main hoặc int main
-
16-08-2014, 03:02 PM #3
Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Xem lại đoạn này nè bạn.
Mã:void nhapMT { for(int i=0;i<m;i++) for(int j=0;j<m;j++) { cout<<"phan tu["<<i<<","<<j<<"]="; cin>>ptu[i][j]; } }
-
16-08-2014, 06:16 PM #4
Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
MÌNH ĐÃ SỬA HẾT LỖI
BẠN XEM LẠI.. NHƯN NÓ KHÔNG CHẠY
#include <iostream>
#include <cstdlib>
#include <stdio.h>
#include <conio.h>
using namespace std;
class matran
{
private:
int m,n;
float ptu[10][10];
public:
matran()
{
}
matran(int x, int y)
{
m = x;
n = y;
}
void nhapMT()
{
for(int i=0;i<m;i++)
for(int j=0;j<m;j++)
{
cout<<"phan tu["<<i<<","<<j<<"]=";
cin>>ptu[i][j];
}
}
void xuatMT()
{
for(int i=0;i<m;i++)
{
cout<<endl;
for(int j=0;j<n;j++)
cout<<ptu[i][j]<<"...";
}
};
int matranDV()
{
for(int i=0;i<m;i++)
for(int j=0;j<m;j++)
{
if((i==j)&&(ptu[i][j]!=1))
return 0;
if((i!=j)&&(ptu[i][j]!=0))
return 0;
}
return 1;
}
void main()
{
matran M(3,3);
M.nhapMT();
M.xuatMT();
if(MT.matranDV()==1)
cout<<"Ma tran don vi!"<<endl;
else
cout<<"Khong phai ma tran don vi!"<<endl;
getch();
}
NGUỒN SỈ ÁO KHOÁC DENIM NỮ TPHCM CHẤT LƯỢNG CAO Bạn muốn nhập sỉ áo khoác denim nữ để bắt đầu việc buôn bán Online phong cách nhưng lại chưa có kinh nghiệm, muốn sắm xưởng sỉ xống áo vừa có thể giải...
Xưởng sỉ áo khoác jeans denim giá...