Chào mừng đến với Diễn đàn lập trình - Cộng đồng lập trình.
Kết quả 1 đến 4 của 4
  1. #1
    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();
    }
    và lỗi của nó là :
    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
    mình đã sửa nhiều cách nhưng vẫn không chạy được là sao mọi người
    Giúp mình,cảm ơn mọi người nhiều

  2. #2
    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

  3. #3
    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];        }    }

  4. #4
    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();
    }

 

 

Quyền viết bài

  • Bạn Không thể gửi Chủ đề mới
  • Bạn Không thể Gửi trả lời
  • Bạn Không thể Gửi file đính kèm
  • Bạn Không thể Sửa bài viết của mình
  •