C++面向对象程序设计 - 类和对象进一步讨论

news2024/9/20 8:07:41

        在C++中,关于面向对象程序设计已经讲了很大篇幅,也例举很多案例,此篇将通过一些习题来进一步了解对象、静态成员、指针、引用、友元、类模板等等相关知识。

一、习题一(构造函数默认参数)

        示例代码:

#include <iostream>
using namespace std;
class Date{
	public:
		Date(int, int, int);
		Date(int, int);
		Date(int);
		Date();
		void display();
	private:
		int month;
		int day;
		int year;
};
Date::Date(int m, int d, int y): month(m), day(d), year(y) {}
Date::Date(int m, int d): month(m), day(d){
	year = 2005;
}
Date::Date(int m): month(m){
	day = 1;
}
Date::Date(){
	month = 1;
	day = 1;
	year = 2005;
}
void Date::display(){
	cout <<month <<"/" <<day <<"/" <<year <<endl;
}
int main(){
	Date d1(10, 13, 2005);
	Date d2(12, 30);
	Date d3(10);
	Date d4;
	d1.display();
	d2.display();
	d3.display();
	d4.display();
	return 0;
}

        如上代码,运行后结果如下图:

1.1 提问

        现在将上述代码中,第5行的构造函数中添加默认参数,即:

Date(int=1, int=1, int=2005);

        分析此程序是否有问题,并分析出错误信息,修改程序后使之能通过编译,得到上图一样结果。

        解答:

        关于构造函数前面也讲过,地址:C++面向对象程序设计 - 构造函数-CSDN博客,在该篇的“六、构造函数添加默认参数”中作了简单阐述。当时时建议大家在写构造函数时,尽量不要使用默认参数,因为一般程序员对此不好把控,编译时会出现错误【call of overloaded 'function_name' is ambiguous】。在构造函数形参中添加默认参数,通常编译器在尝试解析构造函数时发现了多个可能的匹配项,它无法确定应该使用哪一个,因为所有这此匹配项在某种程序上都是可行的。

        将构造函数中添加默认参数代码(错误代码)如下:

#include <iostream>
using namespace std;
class Date{
	public:
		Date(int=1, int=1, int=2005);
		Date(int, int);
		Date(int);
		Date();
		void display();
	private:
		int month;
		int day;
		int year;
};
Date::Date(int m, int d, int y): month(m), day(d), year(y) {}
Date::Date(int m, int d): month(m), day(d){
	year = 2005;
}
Date::Date(int m): month(m){
	day = 1;
}
Date::Date(){
	month = 1;
	day = 1;
	year = 2005;
}
void Date::display(){
	cout <<month <<"/" <<day <<"/" <<year <<endl;
}
int main(){
	Date d1(10, 13, 2005);
	Date d2(12, 30);
	Date d3(10);
	Date d4;
	d1.display();
	d2.display();
	d3.display();
	d4.display();
	return 0;
}

        此时运行时,编译器会报错【[Error] call of overloaded 'Date(int, int)' is ambiguous】- 调用重载的'Date(int, int)'是不明确的。

        上述代码中,在定义d2,d3,d4时,其实构造函数Date(int=1, int=1, int=2005)都是可行的,将会一直匹配第一个构造函数,后面定义的Date(int, int)、Date(int)、Date()将不会被匹配到。所以此题想要解决此问题,将后面三个构造函数删除即可,代码(正确代码)如下:

#include <iostream>
using namespace std;
class Date{
	public:
		Date(int=1, int=1, int=2005);
		void display();
	private:
		int month;
		int day;
		int year;
};
Date::Date(int m, int d, int y): month(m), day(d), year(y) {}
void Date::display(){
	cout <<month <<"/" <<day <<"/" <<year <<endl;
}
int main(){
	Date d1(10, 13, 2005);
	Date d2(12, 30);
	Date d3(10);
	Date d4;
	d1.display();
	d2.display();
	d3.display();
	d4.display();
	return 0;
}

        其运行结果和前面也是一样的。

二、习题二(指针)

2.1 提问一

        建立一个对象数组,内放5个学生的数据(学号、成绩),用指针指向数组首元素,输出第1,3,5个学生的数据。

        解答:

        在前面篇幅讲到指针(C++面向对象程序设计 - 对象指针和this指针-CSDN博客),在“三、对象数组的指针”中讲到把数组赋值给指针变量是指向数组中第一个元素,所以此题代码如下:

#include <iostream>
using namespace std;
class Student{
	private:
		int num;		//学号
		int score;		//成绩
	public:
		Student(int n, int s): num(n), score(s){}
		void display(){
			cout <<"num:" <<num <<", score:" <<score <<endl;
		};
};
int main(){
	Student sArr[5] = {
		Student(1001, 87),
		Student(1002, 98),
		Student(1003, 89),
		Student(1004, 92),
		Student(1005, 81)
	};
	Student *p = sArr;
    //显示第1个
	p->display();	
	//显示第3个
	(p+2)->display();
	//显示第5个
	(p+4)->display();
	return 0;
}

        通过指针的移位,输出指针对应的Student对象数据,结果如下图:

2.2 提问二

        在学生Student对象中设立一个函数max,用指向对象的指针作函数参数,在max函数中找到5个学生中成绩最高者,并输出其学号。

        解答:

        此题让我们首先想到的则是静态成员,这里就先按题目中的方法,在对象中定义一个静态max函数用来找到5名学生中成绩最高者。代码如下:

#include <iostream>
using namespace std;

class Student{
	private:
		int num;		//学号
		int score;		//成绩
	public:
		Student(int n, int s): num(n), score(s){}
		void display(){
			cout <<"num:" <<num <<", score:" <<score <<endl;
		}
		get_num(){ return this->num; }
		get_score(){ return this->score; }
		// 声明获取成绩最高的学生
		static Student max(Student*, int);
};
// 定义静态成员函数max
Student Student::max(Student* stuArr, int size){
	Student maxStu = (*stuArr);	//默认第一个为第大值
	for(int i = 0; i < size; i++){
		if(stuArr[i].get_score() > maxStu.get_score()){
			maxStu = stuArr[i]; 
		}
	}
	return maxStu;
};

int main(){
	Student sArr[5] = {
		Student(1001, 87),
		Student(1002, 98),
		Student(1003, 89),
		Student(1004, 92),
		Student(1005, 81)
	};
	// 显示成绩最高者
	Student h = Student::max(sArr, 5);
	h.display();
	return 0;
}

        运行结果如下图:

2.3 提问三

         对于“提问二”,也可以脱题使用静态数据成员来完成,定义HighNum和HighScore来存储最高者的学号和成绩,并在构造函数中判断初始值谁的成绩最高,其结果也是一样的。代码如下:

#include <iostream>
using namespace std;

class Student{
	private:
		int num;		//学号
		int score;		//成绩
		static int HighNum;		//最高者编号
		static int HighScore;	//最高者成绩
	public:
		Student(int n, int s): num(n), score(s){
			// 判断最大值
			if(s>HighScore){
				HighScore = s;
				HighNum = n;
			}
		}
		void display(){
			cout <<"num:" <<num <<", score:" <<score <<endl;
		}
		// 显示最大值
		static void max(){
			cout <<"num:" <<HighNum <<", score:" <<HighScore <<endl;
		}
};
// 初始化静态数据成员
int Student::HighNum = 0;
int Student::HighScore = 0;

int main(){
	Student sArr[5] = {
		Student(1001, 87),
		Student(1002, 98),
		Student(1003, 89),
		Student(1004, 92),
		Student(1005, 81)
	};
	// 显示成绩最高者
	Student::max();
	return 0;
}

        解答:

        可能有些人在想,这里Student对象中数据成员较少,但如果遇到数据成员较多的,此时输出最高者的信息不是要定义很多对应最高者的数据成员,代码显示会比较臃肿。所以获取最高者,并能输出最高者中所有数据成员信息(不受数据成员限制),明显是记录Student对象最高效的。在这保留最高分这个数据成员,将第另个静态数据成员改为对应的Student对象。代码如下:

#include <iostream>
using namespace std;

class Student{
	private:
		int num;		//学号
		int score;		//成绩
		static int HighScore;	//最高者成绩
		static Student stu;		//最高者
	public:
		Student(int n, int s): num(n), score(s){
			// 判断最大值
			if(s>HighScore){
				HighScore = s;
				stu = (*this);
			}
		}
		void display(){
			cout <<"num:" <<num <<", score:" <<score <<endl;
		}
		// 成绩最高者
		static Student max(){
			return stu;
		}
};
// 初始化静态数据成员
int Student::HighScore = 0;
Student Student::stu = Student(0, 0);

int main(){
	Student sArr[5] = {
		Student(1001, 87),
		Student(1002, 98),
		Student(1003, 89),
		Student(1004, 92),
		Student(1005, 81)
	};
	// 显示成绩最高者
	Student s = Student::max();
	s.display();
	return 0;
}

        此时运行后的结果依然是一样的。

三、习题三(常对象、常指针、引用)

        示例代码:

#include <iostream>
using namespace std;
class Student{
	public:
		Student(int n, float s): num(n), score(s){}
		void change(int n, float s){
			num = n;
			score = s;
		}
		void display(){
			cout <<num <<" " <<score <<endl;
		}
	private:
		int num;
		float score;
};
int main(){
	Student stu(101, 78.5);
	stu.display();
	stu.change(101, 80.5);
	stu.display();
	return 0;
}

        运行结果如下:

3.1 提问一

        将main函数第2行修改为:

const Student stu(101, 78.5);

        解答:如上述方法,主要会出现以下两个错误:

  1. 如果尝试通过const对象来调用非const成员函数,编译器会报错,因非const成员函数需要一个指向非const对象的this指针,而const对象只能提供一个指向const对象的this指针。所以当执行到stu.display()时会报错【[Error] passing 'const Student' as 'this' argument discards qualifiers [-fpermissive]】- 将'const Student'作为'this'参数传递时会放弃限定符。解决方法则是将change成员函数和display成员函数都定义为常成员函数。
  2. 一旦创建一个const对象,它的任何成员都不能被修改。然而试图使用change()函数来修改对象的num和score成员,是不允许的。但是C++中也给出解决方案,可以在数据成员前面添加mutable。否则编译器会报错【[Error] assignment of member 'Student::num' in read-only object】- 在只读对象中分配成员'Student::num'。

        按上述问题进行修改后,程序则可以正常编译并运行,代码如下:

#include <iostream>
using namespace std;
class Student{
	public:
		Student(int n, float s): num(n), score(s){}
		void change(int n, float s) const {
			num = n;
			score = s;
		}
		void display() const {
			cout <<num <<" " <<score <<endl;
		};
	private:
		mutable int num;
		mutable float score;
};
int main(){
	const Student stu(101, 78.5);
	stu.display();
	stu.change(101, 80.5);
	stu.display();
	return 0;
}

3.2 提问二

        将main函数改为以下内容,其他问题扔为示例中代码:

int main(){
	Student stu(101, 78.5);
	const Student *p = &stu;
	p->display();
	p->change(101, 80.5);
	p->display();
	return 0;
}

        解答:这题是先定义一个Student类型的对象,并使用一个指向const Student的指针来指向这个对象,一般称为常对象的指针变量。即然是常对象,则与“提问一”中是一样的问题,指针变量p也只能调用常成员函数,以及数据成员无法修改等问题。所以按“提问一”中代码修改即可,代码如下:

#include <iostream>
using namespace std;
class Student{
	public:
		Student(int n, float s): num(n), score(s){}
		void change(int n, float s) const {
			num = n;
			score = s;
		}
		void display() const {
			cout <<num <<" " <<score <<endl;
		}
	private:
		mutable int num;
		mutable float score;
};
int main(){
	Student stu(101, 78.5);
	const Student *p = &stu;
	p->display();
	p->change(101, 80.5);
	p->display();
	return 0;
}

3.3 提问三

        把“提问二”中的第3行改为以下内容,其他问题扔为示例中代码:

Student * const p = &stu;

        解答:这里是创建了一个指向Student对象的常量指针,这个const修饰的是指针p本身,而不是所指向的Student对象。这意味着常指针这初始化指向&stu后,不能重新赋值指针,但可以通过p修改它所指向的Student对象的内容。所以不会影响示例中Student对象,代码如下:

#include <iostream>
using namespace std;
class Student{
	public:
		Student(int n, float s): num(n), score(s){}
		void change(int n, float s)  {
			num = n;
			score = s;
		}
		void display()  {
			cout <<num <<" " <<score <<endl;
		}
	private:
		int num;
		float score;
};
int main(){
	Student stu(101, 78.5);
	Student * const p = &stu;
	p->display();
	p->change(101, 80.5);
	p->display();
	return 0;
}

3.4 提问四

        在程序中增加一个fun函数,在main函数中调用fun函数,在fun函数中调用change和display函数,在fun函数中使用对象引用(Student &)作为形参。

        解答:一个变量的引用其实就是变量的别名,变量名和引用名指向是同一段内存单元,所以在fun函数中无修改,直接通过引用的别名调用即可。代码如下:

#include <iostream>
using namespace std;
class Student{
	public:
		Student(int n, float s): num(n), score(s){}
		void change(int n, float s)  {
			num = n;
			score = s;
		}
		void display()  {
			cout <<num <<" " <<score <<endl;
		}
	private:
		int num;
		float score;
};
// 新增的fun函数
void fun(Student &s){
	s.display();
	s.change(101, 80.5);
	s.display();
}
int main(){
	Student stu(101, 78.5);
	fun(stu);
	return 0;
}

四、习题四(友元)

        在上篇(C++面向对象程序设计 - 静态成员、友元-CSDN博客)中已经列举了友元的相关内容,需要了解的朋友可以前去查看。

        示例代码:

#include <iostream>
using namespace std;
class Date;
class Time{
	public:
		Time(int, int, int);
		void display(Date &);
	private:
		int hour;
		int minute;
		int second;	
};
class Date{
	public:
		Date(int, int, int);
		// 声明Time类中的display函数为本类的友元成员函数
		friend void Time::display(Date &);
	private:
		int year;
		int month;
		int day;
};
Time::Time(int h, int m, int s): hour(h), minute(m), second(s){}
void Time::display(Date &d){
	cout <<d.year <<"/" <<d.month <<"/" <<d.day <<" " <<hour <<":" <<minute <<":" <<second <<endl;
}
Date::Date(int y, int m, int d): year(y), month(m), day(d){}
int main(){
	Time t1(10, 13, 56);
	Date d1(2024, 12, 25);
	t1.display(d1);
	return 0;
}

        运行输出结果如下:

4.1 提问一

        将示例中的display函数不放在Time类中,而作为类外的普通函数,然后分别在Time和Date类中将display声明为友元函数。在主函数中调用display函数,display函数分别引用Time和Date两个类的对象的私有数据,输出年、月、日和时、分、秒。

        解答:此题是将display定义为友元函数,比较简单,将display在Time和Date类中声明为友元函数即可。另外对构造函数也作了些调整,将在类体外定义改为类体内定义构造函数,并初始化数据成员。代码如下:

#include <iostream>
using namespace std;
class Date;
class Time{
	public:
		Time(int h, int m, int s): hour(h), minute(m), second(s){}
		// 声明display为友函数
		friend void display(Time &, Date &);
	private:
		int hour;
		int minute;
		int second;
};
class Date{
	public:
		Date(int y, int m, int d): year(y), month(m), day(d){}
		// 声明display为友函数
		friend void display(Time &, Date &);
	private:
		int year;
		int month;
		int day;	
};
// 定义display函数 - 显示时间
void display(Time &t, Date &d){
	cout <<d.year <<'/' <<d.month <<'/' <<d.day <<' ' <<t.hour <<':' <<t.minute <<':' <<t.second <<endl;
}
int main(){
	Time t(23, 59, 59);
	Date d(2024, 4, 14);
	// 显示时间
	display(t, d);
	return 0;
}

4.2 提问二

        将示例中Date类声明为Time类的友元类,通过Date类中的display函数引用Time类对象的私有数据,输出年、月、日和时、分、秒。

        解答:此题是将示例中friend友元声明函数到Time中,将display函数变成Date的成员函数即可;并且注意修改Date类和Time定义顺序,第一行声明的class Date需要修改为class Time。代码如下:

#include <iostream>
using namespace std;
class Time;
class Date{
	public:
		Date(int y, int m, int d): year(y), month(m), day(d){}
		void display(Time &);
	private:
		int year;
		int month;
		int day;	
};
class Time{
	public:
		Time(int h, int m, int s): hour(h), minute(m), second(s){}
        // 声明Date类中display为Time类的友函数
		friend void Date::display(Time &);
	private:
		int hour;
		int minute;
		int second;
};
void Date::display(Time &t){
	cout <<year <<'/' <<month <<'/' <<day <<' ' <<t.hour <<':' <<t.minute <<':' <<t.second <<endl;
}
int main(){
	Time t(23, 59, 59);
	Date d(2024, 4, 14);
	// 显示时间
	d.display(t);
	return 0;
}

五、习题五(类模板)

        示例代码:

#include <iostream>
using namespace std;
template<class numtype>
class Compare{
	public:
		Compare(numtype a, numtype b){
			x = a;
			y = b;
		}
		// 获取最大值
		numtype max(){
			return x>y?x:y;
		}
		// 获取最小值
		numtype min(){
			return x>y?y:x;
		}
	private:
		numtype x, y;
};
int main(){
	Compare<int> cp1(3, 7);
	cout <<cp1.max() <<" is the Maximum of two integer numbers." <<endl;
	cout <<cp1.min() <<" is the Minimum of two integer numbers." <<endl <<endl;
	
	Compare<float> cp2(45.78f, 93.6f);
	cout <<cp2.max() <<" is the Maximum of two float numbers." <<endl;
	cout <<cp2.min() <<" is the Minimum of two float numbers." <<endl <<endl;
	
	Compare<char> cp3('a', 'A');
	cout <<cp3.max() <<" is the Maximum of two char numbers." <<endl;
	cout <<cp3.min() <<" is the Minimum of two char numbers." <<endl <<endl;
	return 0;
}

        运行结果如下图:

5.1 提问

        将示例中程序改写为在类模板外定义各成员函数。

        解答:如果成员函数是在类模板外定义的,则不能用一般定义类成员函数的形式。需要注意以下几点:

  1. 在类模板内部,构造函数只是被声明了,没有定义体。
  2. 在类模板外部,构造函数的定义使用了template<class numtype>来指明它是一个模板类的成员函数。
  3. 构造函数的定义后跟着Compare<numtype>::Compare(numtype a, numtype b),这表示我们正在定义Compare模板类的构造函数。

        在类模板外部定义成员函数,代码如下:

#include <iostream>
using namespace std;
template<class numtype>
class Compare{
	public:
		Compare(numtype, numtype);	//声明构造函数
		numtype max();		//声明成员函数max
		numtype min();		//声明成员函数min
	private:
		numtype x, y;
};
// 在类模板外定义构造函数
template<class numtype>
Compare<numtype>::Compare(numtype a, numtype b): x(a), y(b){}
// 在类模板外定义成员函数max、
template<class numtype>
numtype Compare<numtype>::max(){
	return x>y?x:y;
}
// 在类模板外定义成员函数min
template<class numtype>
numtype Compare<numtype>::min(){
	return x>y?y:x;
}
int main(){
	Compare<int> cp1(3, 7);
	cout <<cp1.max() <<" is the Maximum of two integer numbers." <<endl;
	cout <<cp1.min() <<" is the Minimum of two integer numbers." <<endl <<endl;
	
	Compare<float> cp2(45.78f, 93.6f);
	cout <<cp2.max() <<" is the Maximum of two float numbers." <<endl;
	cout <<cp2.min() <<" is the Minimum of two float numbers." <<endl <<endl;
	
	Compare<char> cp3('a', 'A');
	cout <<cp3.max() <<" is the Maximum of two char numbers." <<endl;
	cout <<cp3.min() <<" is the Minimum of two char numbers." <<endl <<endl;
	return 0;
}

       如在在类模板体外定义成员函数,第1行是声明类模板,第2行第一个numtype是虚拟类型名,后面Compare<numtype>是一个整体,是带参的类;表示所定义的max函数是在类Compare<numtype>的作用域内的;在定义对象时,用户要指定实际的类型(如int),进行编译时就会将类模板中的虚拟类型名numtype全部用实际的类型代替,这样Compare<numtype>就相当于一个实际的类。

        类模板声明和使用在上篇(C++面向对象程序设计 - 类模板-CSDN博客)中已讲解,在“四、归纳”中也归纳几种形式。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1597529.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

主流App UI设计,7个在线平台供您选择!

在数字时代&#xff0c;用户界面&#xff08;UI&#xff09;设计变得非常重要&#xff0c;因为良好的UI设计可以改善用户体验&#xff0c;增强产品吸引力。随着技术的发展&#xff0c;越来越多的应用程序 ui在线设计网站的出现为设计师和团队提供了一种全新的创作方式。本文将盘…

关于Wordpress的操作问题1:如何点击菜单跳转新窗口

1.如果打开&#xff0c;外观-菜单-菜单结构内&#xff0c;没有打开新窗口属性&#xff0c;如图&#xff1a; 2.在页面的最上部&#xff0c;点开【显示选项】&#xff0c;没有这一步&#xff0c;不会出现新跳转窗口属性 3.回到菜单结构部分&#xff0c;就出现了

Mysql嵌套查询太简单了

1、子查询的分类 不相关查询&#xff1a; 子查询能独立执行 相关查询&#xff1a; 子查询不能独立运行 相关查询的执行顺序&#xff1a; 首先取外层查询中表的第一个元组,根据它与内层查询相关的属性值处理内层查询, 若WHERE子句返回值为真&#xff0c;则取此元组放入结果…

CSS基础:margin属性4种值类型,4个写法规则详解

你好&#xff0c;我是云桃桃。 一个希望帮助更多朋友快速入门 WEB 前端的程序媛。大专生&#xff0c;一枚程序媛&#xff0c;感谢关注。回复 “前端基础题”&#xff0c;可免费获得前端基础 100 题汇总&#xff0c;回复 “前端工具”&#xff0c;可获取 Web 开发工具合集 268篇…

PaddleOCR训练自己模型(1)----数据准备

一、下载地址&#xff1a; PaddleOCR开源代码&#xff08;下载的是2.6RC版本的&#xff0c;可以根据自己需求下载&#xff09; 具体环境安装就不详细介绍了&#xff0c; 挺简单的&#xff0c;也挺多教程的。 二、数据集准备及制作 &#xff08;1&#xff09;下载完代码及配置…

Navicat for MySQL 使用基础与 SQL 语言的DDL

一、目的&#xff1a; Navicat for MySQL 是一套专为 MySQL 设计的高性能数据库管理及开发 工具。它可以用于任何版本 3.21 或以上的 MySQL 数据库服务器&#xff0c;并支持大 部份 MySQL 最新版本的功能&#xff0c;包括触发器、存储过程、函数、事件、视图、 管理用户等。…

软件工程及开发模型

根据希赛相关视频课程汇总整理而成&#xff0c;个人笔记&#xff0c;仅供参考。 软件工程的基本要素包括方法、工具和&#xff08;过程&#xff09; 方法&#xff1a;完成软件开发的各项任务的技术方法&#xff1b; 工具&#xff1a;运用方法而提供的软件工程支撑环境&#xff…

数据结构 -- 二分查找

本文主要梳理了二分查找算法的几种实现思路&#xff0c;基本概念参考 顺序、二分、哈希查找的区别及联系_生成一个大小为10万的有序数组,随机查找一个元素,分别采用顺序查找和二分查找方式-CSDN博客 1、基本概念 &#xff08;1&#xff09;前提条件&#xff1a;待查找数据必须…

Leetcode二叉树刷题

给你一个二叉树的根节点 root &#xff0c; 检查它是否轴对称。 示例 1&#xff1a; 输入&#xff1a;root [1,2,2,3,4,4,3] 输出&#xff1a;true public boolean isSymmetric(TreeNode root) {if(rootnull)return true;return compare(root.left,root.right);}public boole…

【Unity】游戏场景添加后处理特效PostProcessing

添加后处理特效PostProcessing 添加雾效果后处理何为后处理&#xff1f;添加后处理特效 添加雾效果 依次点击Window -> Rendering -> Lighting添加Lighting面板。 点击Lighting里面的Environment&#xff0c;找到Other Setting 将Fog选项勾选 更改下方的颜色 调整雾的浓…

自然语言处理: 第二十七章LLM训练超参数

前言: LLM微调的超参大致有如下内容,在本文中&#xff0c;我们针对这些参数进行解释 training_arguments TrainingArguments(output_dir"./results",per_device_train_batch_size4,per_device_eval_batch_size4,gradient_accumulation_steps2,optim"adamw_8bi…

JavaSE图书管理系统

JavaSE图书管理系统 思路一.Main方法二.User包1.User类2.NormaUser类3.AdminUser类三.book包1.BookList类2.Book类四.operation包1.IOPeration接口2.AddOperation类新增图书3.BorrowOperation类借阅图书4.DelOperation类删除图书5.FindOperation类查找图书6.ReturnOperation类归…

Unity解决:导出安卓apk 安装时报错:应用未安装:软件包似乎无效

Unity2018.4.36 导出安卓apk 安装时报错&#xff1a;应用未安装&#xff1a;软件包似乎无效 解决办法&#xff1a;因为安装到安卓12 需要添加添加过滤规则 在AS工程AndroidManifest.xml 添加过滤规则即可。 android:exported"true"

初识ansible服务剧本playbook及剧本编写实例

目录 1、playbook剧本文件概念 1.1 剧本文件的结构由4部分组成 2、配置实例 实例1-编写一个实现批量安装mariadb数据库的剧本 实例2-编写一个创建一个目录/backup,并在目录喜爱创建01.txt文件的剧本 实例3-编写一个添加定时同步时间的定时任务剧本 错误反思 1、playbook剧…

MDK-ARM Keil5.38 下载安装环境搭建

一、keil软件介绍 KEIL是公司的名称&#xff0c;有时候也指KEIL公司的所有软件开发工具&#xff0c;目前2005年Keil由ARM公司收购&#xff0c;成为ARM的公司之一。 MDK&#xff08;Microcontroller Development Kit&#xff09; 也称MDK-ARM、KEIL MDK、RealView MDK、KEIL For…

不需要GPU就可以玩转模型,同时支持本地化部署

简单一款不需要GPU就可以在Win 机器跑的模型&#xff1a;Ollama&#xff1b;用于本地运行和部署大型语言模型&#xff08;LLMs&#xff09;的开源工具 关于Ollama的简要介绍 平台兼容性&#xff1a;Ollama支持多种操作系统&#xff0c;包括macOS、Linux和Windows&#xff0c;…

linux系统USB/IP远程共享USB设备 —— 筑梦之路

概述 USB/IP 是一个开源项目&#xff0c;已合入 Kernel&#xff0c;在 Linux 环境下可以通过使用 USB/IP 远程共享 USB 设备。 USB Client&#xff1a;使用USB的终端&#xff0c;将server共享的usb设备挂载到本地。 USB Server&#xff1a;分享本地的usb设备至远程。 架构原理…

蓝桥杯2024年第十五届省赛真题-R 格式(高精度乘法 + 加法)

本题链接&#xff1a;蓝桥杯2024年第十五届省赛真题-R 格式 - C语言网 题目&#xff1a;​​​​​​​ 样例&#xff1a; 输入 2 3.14 输出 13 思路&#xff1a; 根据题意&#xff0c;结合数据范围&#xff0c;这是一道模板的高精度乘以低精度问题。 题意是double 类型 d 与…

vue3从精通到入门4:diff算法的实现

Vue 3 的 diff 算法相较于 Vue 2 有了一些改进和优化&#xff0c;主要是为了应对更复杂的组件结构和更高的性能需求。 以下是 Vue 3 diff 算法在处理列表更新时的大致步骤&#xff1a; 头头比较&#xff1a;首先&#xff0c;比较新旧列表的头节点&#xff08;即第一个节点&…

参会记录|全国多媒体取证暨第三届多媒体智能安全学术研讨会(MAS‘2024)

前言&#xff1a;2024年4月13日上午&#xff0c;我与实验室的诸位伙伴共聚江西南昌的玉泉岛大酒店&#xff0c;参加了为期一天半的全国多媒体取证暨第三届多媒体智能安全学术研讨会&#xff08;MAS’2024&#xff09;。本届学术研讨会由江西省计算机学会、江西省数字经济学会主…