矩阵转址的一般算法

来源:互联网 发布:mac uefi 编辑:程序博客网 时间:2024/05/16 02:20

再写一段练习程序:

编译之后成功运行。代码结构方面,顺序有待改进,没有用模版,只能输入intType数据。

嗯,大概就是这样= =

////  main.cpp//  矩阵转址//  //  Created by FIREDOM on 3/31/13.//  Copyright (c) 2013 firedom. All rights reserved.//#include "File.h"int main(){    class main Tc;    Tc.mainFunc();    return (0);}

////  File.h//  矩阵转址////  Created by FIREDOM on 3/31/13.//  Copyright (c) 2013 firedom. All rights reserved.//#ifndef ____________File__#define ____________File__#include <iostream>const int N = 30;class matrx{private:    int a[N][N], b[N][N];    int i, j;    int length, height;    public:    void inputArea();    void inputData();    void display();};class main{private:    public:    void mainFunc();};#endif /* defined(____________File__) */

//  File.cpp//  矩阵转址////  Created by FIREDOM on 3/31/13.//  Copyright (c) 2013 firedom. All rights reserved.//#include "File.h"void main::mainFunc(){    matrx T;    T.inputArea();    T.inputData();    T.display();}void matrx::inputArea(){    std::cout << "请输入数组的长宽:" << std::endl;    std::cin >> length >> height;}void matrx::inputData(){    std::cout << "请输入数组的元素:" << std::endl;    for(i = 0; i < length; i++)        for(j = 0; j < height; j++)        {            std::cin >> a[i][j];            b[j][i] = a[i][j];        }}void matrx::display(){    std::cout << "原矩阵为:" << std::endl;    for(i = 0; i < length; i++)    {        for(j = 0; j < height; j++)        {            std::cout << a[i][j] << " ";        }        std::cout << std::endl;    }    std::cout << "转置矩阵为:" << std::endl;    for(i = 0; i < height; i++)    {        for(j = 0; j < length; j++)        {            std::cout << b[i][j] << " ";        }        std::cout << std::endl;    }}


原创粉丝点击