This commit is contained in:
iridiumR 2022-03-15 17:09:12 +08:00
parent f7d1dd1da3
commit cacff0155b
3 changed files with 86 additions and 31 deletions

View file

@ -1,42 +1,22 @@
/*
* @Author: iR
* @Date: 2022-03-11 20:22:54
* @Date: 2022-03-15 16:47:44
* @LastEditors: iR
* @LastEditTime: 2022-03-12 14:13:14
* @LastEditTime: 2022-03-15 16:52:26
* @FilePath: \Code\1-1c\main.cpp
* @Description:
*
* Copyright (c) 2022 by iR, All Rights Reserved.
* @Mail: i@iridium.cyou
*/
#include "../inc/matrix.hpp"
#include <stdio.h>
int main()
{
double data[] = {1, 2, 3, 4};
Matrix<double> a(2, 2, data);
std::cout << "a" << std::endl
<< a.at(0, 0) << " " << a.at(1, 0) << std::endl
<< a.at(0, 1) << " " << a.at(1, 1) << std::endl;
std::cout << "+=" << std::endl;
Matrix<double> b(2, 2, data);
std::cout << "b" << std::endl
<< b.at(0, 0) << " " << b.at(1, 0) << std::endl
<< b.at(0, 1) << " " << b.at(1, 1) << std::endl;
std::cout << "Answer" << std::endl;
a += b;
std::cout << "a" << std::endl
<< a.at(0, 0) << " " << a.at(1, 0) << std::endl
<< a.at(0, 1) << " " << a.at(1, 1) << std::endl;
std::cout << "c=a+b" << std::endl;
Matrix<double> c = a + b;
std::cout << "Answer" << std::endl;
std::cout << "c" << std::endl
<< c.at(0, 0) << " " << c.at(1, 0) << std::endl
<< c.at(0, 1) << " " << c.at(1, 1) << std::endl;
int data[] = {1, 2, 3, 4};
Matrix<int> b;
Matrix<int> a(2, 2, data);
b = a;
a.at(0, 0) = 5;
printf("[%d,%d,%d,%d]\n", a.at(0, 0), a.at(0, 1), a.at(1, 0), a.at(1, 1));
printf("[%d,%d,%d,%d]", b.at(0, 0), b.at(0, 1), b.at(1, 0), b.at(1, 1));
return 0;
}
}

View file

@ -0,0 +1,42 @@
/*
* @Author: iR
* @Date: 2022-03-11 20:22:54
* @LastEditors: iR
* @LastEditTime: 2022-03-15 17:06:14
* @FilePath: \Code\1-1d\main.cpp
* @Description:
*
* Copyright (c) 2022 by iR, All Rights Reserved.
*/
#include "../inc/matrix.hpp"
#include <stdio.h>
int main()
{
double data[] = {6, 2, 5, 4};
Matrix<double> a(2, 2, data);
std::cout << "a" << std::endl
<< a.at(0, 0) << " " << a.at(1, 0) << std::endl
<< a.at(0, 1) << " " << a.at(1, 1) << std::endl;
std::cout << "+=" << std::endl;
Matrix<double> b(2, 2, data);
std::cout << "b" << std::endl
<< b.at(0, 0) << " " << b.at(1, 0) << std::endl
<< b.at(0, 1) << " " << b.at(1, 1) << std::endl;
std::cout << "Answer" << std::endl;
a += b;
std::cout << "a" << std::endl
<< a.at(0, 0) << " " << a.at(1, 0) << std::endl
<< a.at(0, 1) << " " << a.at(1, 1) << std::endl;
std::cout << "c=a+b" << std::endl;
Matrix<double> c = a + b;
std::cout << "Answer" << std::endl;
std::cout << "c" << std::endl
<< c.at(0, 0) << " " << c.at(1, 0) << std::endl
<< c.at(0, 1) << " " << c.at(1, 1) << std::endl;
return 0;
}

View file

@ -0,0 +1,33 @@
/*
* @Author: iR
* @Date: 2022-03-15 07:30:23
* @LastEditors: iR
* @LastEditTime: 2022-03-15 17:05:13
* @FilePath: \Code\1-3a\main.cpp
* @Description:
* @Mail: i@iridium.cyou
*/
#include <iostream>
using namespace std;
class Parent
{ // 基类
public:
void f1() { cout << "This is parent-f1" << endl; }
virtual void f2() { cout << "This is parent-f2" << endl; } // 声明f2是虚函数
} parent;
class Child : public Parent
{ // 派生类
public:
void f1() { cout << "This is child-f1" << endl; }
void f2() { cout << "This is child-f2" << endl; }
} child;
int main(int argc, char *argv[])
{
Parent *p = new Child; // 定义一个基类指针
p->f1(); // 执行哪个f1
p->f2(); // 执行哪个f2
delete p;
return 0;
}