OOP HomeWork
This commit is contained in:
BIN
oop_hw1/01_面向对象程序设计上机实验一.docx
Normal file
BIN
oop_hw1/01_面向对象程序设计上机实验一.docx
Normal file
Binary file not shown.
BIN
oop_hw1/01_面向对象程序设计上机实验一_参考答案.docx
Normal file
BIN
oop_hw1/01_面向对象程序设计上机实验一_参考答案.docx
Normal file
Binary file not shown.
5
oop_hw1/oop_hw1_1/Func1.cpp
Normal file
5
oop_hw1/oop_hw1_1/Func1.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
#include "func.h"
|
||||
|
||||
int f1(int num) {
|
||||
return g1(num * 2);
|
||||
}
|
||||
8
oop_hw1/oop_hw1_1/Func2.cpp
Normal file
8
oop_hw1/oop_hw1_1/Func2.cpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#include "func.h"
|
||||
|
||||
int g1(int num) {
|
||||
return num * num;
|
||||
}
|
||||
int g2(int num) {
|
||||
return f1(num * 3);
|
||||
}
|
||||
7
oop_hw1/oop_hw1_1/MyMain.cpp
Normal file
7
oop_hw1/oop_hw1_1/MyMain.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <iostream>
|
||||
#include "func.h"
|
||||
using namespace std;
|
||||
int main(int argc, char * argv[]) {
|
||||
cout << g2(10) << endl;
|
||||
return 0;
|
||||
}
|
||||
9
oop_hw1/oop_hw1_1/func.h
Normal file
9
oop_hw1/oop_hw1_1/func.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
#ifndef FUNC_H
|
||||
#define FUNC_H
|
||||
|
||||
int f1(int num);
|
||||
int g1(int num);
|
||||
int g2(int num);
|
||||
|
||||
#endif
|
||||
14
oop_hw1/oop_hw1_2/main.cpp
Normal file
14
oop_hw1/oop_hw1_2/main.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <iostream>
|
||||
#include "print_this.h"
|
||||
#include "print_that.h"
|
||||
extern int print_count;
|
||||
|
||||
int main() {
|
||||
#ifdef DO_THIS
|
||||
print_this("Hello");
|
||||
#else
|
||||
print_that("Hello");
|
||||
#endif
|
||||
std :: cout << "Print called " << print_count << " times." << std::endl;
|
||||
return 0;
|
||||
}
|
||||
7
oop_hw1/oop_hw1_2/print.cpp
Normal file
7
oop_hw1/oop_hw1_2/print.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <iostream>
|
||||
#include "print.h"
|
||||
int print_count = 0;
|
||||
void print(const std::string& s) {
|
||||
++print_count;
|
||||
std::cout << s << std::endl;
|
||||
}
|
||||
6
oop_hw1/oop_hw1_2/print.h
Normal file
6
oop_hw1/oop_hw1_2/print.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#ifndef PRINT_H
|
||||
#define PRINT_H
|
||||
void print(const std::string& s);
|
||||
#endif
|
||||
5
oop_hw1/oop_hw1_2/print_that.cpp
Normal file
5
oop_hw1/oop_hw1_2/print_that.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
#include "print.h"
|
||||
#include "print_that.h"
|
||||
void print_that(const std::string& s) {
|
||||
print("That: " + s);
|
||||
}
|
||||
7
oop_hw1/oop_hw1_2/print_that.h
Normal file
7
oop_hw1/oop_hw1_2/print_that.h
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
#pragma once
|
||||
#include <string>
|
||||
#ifndef PRINT_THAT_H
|
||||
#define PRINT_THAT_H
|
||||
void print_that(const std::string& s);
|
||||
#endif
|
||||
5
oop_hw1/oop_hw1_2/print_this.cpp
Normal file
5
oop_hw1/oop_hw1_2/print_this.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
#include "print.h"
|
||||
#include "print_this.h"
|
||||
void print_this(const std::string& s) {
|
||||
print("This: " + s);
|
||||
}
|
||||
6
oop_hw1/oop_hw1_2/print_this.h
Normal file
6
oop_hw1/oop_hw1_2/print_this.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#ifndef PRINT_THIS_H
|
||||
#define PRINT_THIS_H
|
||||
void print_this(const std::string& s);
|
||||
#endif
|
||||
17
oop_hw1/oop_hw1_3/main.cpp
Normal file
17
oop_hw1/oop_hw1_3/main.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#include <iostream>
|
||||
double average(int arr[], int size) {
|
||||
int sum = 0;
|
||||
for (int i = 0; i < size; ++i) sum += arr[i];
|
||||
return (double)sum / size;
|
||||
}
|
||||
using namespace std;
|
||||
int main() {
|
||||
int n;
|
||||
cin >> n;
|
||||
int * a = new int[n];
|
||||
for (int i = 0;i < n;i++) {
|
||||
cin >> a[i];
|
||||
}
|
||||
cout << average(a, n);
|
||||
return 0;
|
||||
}
|
||||
11
oop_hw1/oop_hw1_4/main.cpp
Normal file
11
oop_hw1/oop_hw1_4/main.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#include <iostream>
|
||||
#include "t_area.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
double a, b, c;
|
||||
cin >> a >> b >> c;
|
||||
cout << triangle_area(a,b,c) << endl;
|
||||
return 0;
|
||||
}
|
||||
5
oop_hw1/oop_hw1_4/t_area.cpp
Normal file
5
oop_hw1/oop_hw1_4/t_area.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
#include <cmath>
|
||||
double triangle_area(double a, double b, double c) {
|
||||
double s = (a + b + c) / 2;
|
||||
return sqrt(s * (s - a) * (s - b) * (s - c));
|
||||
}
|
||||
8
oop_hw1/oop_hw1_4/t_area.h
Normal file
8
oop_hw1/oop_hw1_4/t_area.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
#ifndef tarea
|
||||
#define tarea
|
||||
|
||||
double triangle_area(double a, double b, double c);
|
||||
|
||||
|
||||
#endif // !tarea
|
||||
7
oop_hw1/oop_hw1_5/check_num.h
Normal file
7
oop_hw1/oop_hw1_5/check_num.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
#ifndef testchar
|
||||
#define testchar
|
||||
|
||||
bool is_digit(char ch);
|
||||
|
||||
#endif // !testchar
|
||||
13
oop_hw1/oop_hw1_5/main.cpp
Normal file
13
oop_hw1/oop_hw1_5/main.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <iostream>
|
||||
#include "check_num.h"
|
||||
|
||||
using namespace std;
|
||||
int main()
|
||||
{
|
||||
char ch;
|
||||
for (int i = 0;i < 10;i++) {
|
||||
cin >> ch;
|
||||
cout << is_digit(ch)<<endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
3
oop_hw1/oop_hw1_5/testchar.cpp
Normal file
3
oop_hw1/oop_hw1_5/testchar.cpp
Normal file
@@ -0,0 +1,3 @@
|
||||
bool is_digit(char ch) {
|
||||
return ch >= '0' && ch <= '9';
|
||||
}
|
||||
BIN
oop_hw1/oop_hw1_5/测试截图1_5.jpg
Normal file
BIN
oop_hw1/oop_hw1_5/测试截图1_5.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 193 KiB |
16
oop_hw1/oop_hw1_6/main.cpp
Normal file
16
oop_hw1/oop_hw1_6/main.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include <iostream>
|
||||
#include "sort.h"
|
||||
|
||||
using namespace std;
|
||||
int main() {
|
||||
int d, e;
|
||||
cin >> d >> e;
|
||||
sort_two(d, e);
|
||||
int a, b, c;
|
||||
cin >> a >> b >> c;
|
||||
sort_three(a, b, c);
|
||||
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl;
|
||||
cout << d << e <<endl;
|
||||
cout << a << b << c;
|
||||
return 0;
|
||||
}
|
||||
9
oop_hw1/oop_hw1_6/sort.cpp
Normal file
9
oop_hw1/oop_hw1_6/sort.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include <algorithm>
|
||||
void sort_two(int& a, int& b) {
|
||||
if (a < b) std::swap(a, b);
|
||||
}
|
||||
void sort_three(int& a, int& b, int& c) {
|
||||
if (a < b) std::swap(a, b);
|
||||
if (a < c) std::swap(a, c);
|
||||
if (b < c) std::swap(b, c);
|
||||
}
|
||||
7
oop_hw1/oop_hw1_6/sort.h
Normal file
7
oop_hw1/oop_hw1_6/sort.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
#ifndef sort
|
||||
#define sort
|
||||
void sort_three(int& a, int& b, int& c);
|
||||
void sort_two(int& d, int& e);
|
||||
|
||||
#endif // !sort
|
||||
BIN
oop_hw1/oop_hw1_6/测试截图1_6.jpg
Normal file
BIN
oop_hw1/oop_hw1_6/测试截图1_6.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 220 KiB |
14
oop_hw1/oop_hw1_7/fib.cpp
Normal file
14
oop_hw1/oop_hw1_7/fib.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <iostream>
|
||||
long& smaller(long& a, long& b) { return (a < b) ? a : b; }
|
||||
long& bigger(long& a, long& b) { return (a >= b) ? a : b; }
|
||||
|
||||
void fibe(int count) {
|
||||
long a = 1, b = 1;
|
||||
for (int i = 0; i < count; i++) {
|
||||
long& min = smaller(a, b);
|
||||
long& max = bigger(a, b);
|
||||
min = a + b;
|
||||
std::cout << max << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
9
oop_hw1/oop_hw1_7/fib.h
Normal file
9
oop_hw1/oop_hw1_7/fib.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
#ifndef fib
|
||||
#define fib
|
||||
|
||||
long& smaller(long& a, long& b);
|
||||
long& bigger(long& a, long& b);
|
||||
void fibe(int count);
|
||||
|
||||
#endif // !fib
|
||||
10
oop_hw1/oop_hw1_7/main.cpp
Normal file
10
oop_hw1/oop_hw1_7/main.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <iostream>
|
||||
#include "fib.h"
|
||||
|
||||
using namespace std;
|
||||
int main() {
|
||||
int n;
|
||||
cin >> n;
|
||||
fibe(n);
|
||||
return 0;
|
||||
}
|
||||
43
oop_hw1/oop_hw1_9/main.cpp
Normal file
43
oop_hw1/oop_hw1_9/main.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class Pen {
|
||||
public:
|
||||
void write() {}
|
||||
};
|
||||
|
||||
class FountainPen : public Pen {
|
||||
public:
|
||||
void refill() {}
|
||||
};
|
||||
|
||||
class File {
|
||||
public:
|
||||
std::string name;
|
||||
};
|
||||
|
||||
class Directory {
|
||||
public:
|
||||
std::vector<File> files;
|
||||
};
|
||||
|
||||
class Printer {
|
||||
public:
|
||||
void print(const std::string& doc) {}
|
||||
};
|
||||
|
||||
class Monitor {
|
||||
public:
|
||||
void display(const std::string& img) {}
|
||||
};
|
||||
|
||||
class Sun {
|
||||
public:
|
||||
void shine() {}
|
||||
};
|
||||
|
||||
class Moon {
|
||||
public:
|
||||
void reflect() {}
|
||||
};
|
||||
BIN
oop_hw1/上机测试1 (1).pdf
Normal file
BIN
oop_hw1/上机测试1 (1).pdf
Normal file
Binary file not shown.
Reference in New Issue
Block a user