C++PTA习题总结(二)_给出下面的人员基类框架: class person { protected: string name-程序员宅基地

技术标签: c++  PTA  

第五章 继承类:派生类

1.在protected保护继承中,对于垂直访问等同于公有继承,对于水平访问等同于私有继承。T
2.下列程序的执行结果为 C

#include <iostream>
using namespace std;

class A {
public:
    A() {     cout << "1";    }
    ~A() {    cout << "2";    }
};
class B: public A {
public:
    B() {    cout << "3";    }
    ~B() {    cout << "4";    }
};
int main() {
    B b;
    return 0;
}

A.1234
B.1324
C.1342
D.3142
3.下列关于派生类构造函数和析构函数的说法中,错误的是 D

A. 派生类的构造函数会隐含调用基类的构造函数
B. 如果基类声明了带有形参表的构造函数,则派生类就应当声明构造函数
C. 在建立派生类对象时,先调用基类的构造函数,再调用派生类的构造函数
D. 在销毁派生类对象时,先调用基类的析构函数,再调用派生类的析构函数

4.建立派生类对象时, 3种构造函数分别是a(基类的构造函数)、b(成员对象的构造函数)、c(派生类的构造函数),这3种构造函数的调用顺序为 A

A. abc
B. acb
C. cab
D. cba

5.从shape类派生出一个直角三角形类RTriangle
从shape类派生出一个直角三角形类RTriangle类(regular triangle)。两条直角边长作为RTriangle类的私有成员,类中包含参数为直角边的构造方法。
class shape {// 抽象类
public:
virtual double getArea()=0;// 求面积

virtual double getPerimeter()=0; // 求周长};
直角三角形类名:RTriangle
直角三角形类的构造函数原型如下:
RTriangle(double a, double b);
其中 a 和 b 都是直角三角形的两条直角边。
裁判测试程序样例:
#include
#include
using namespace std;

class shape {// 抽象类
public:
virtual double getArea()=0;// 求面积
virtual double getPerimeter()=0; // 求周长
};
//你提交的代码将嵌入到这里

int main()
{
double a,b;
cin>>a>>b;
RTriangle t(a,b);
cout<<t.getArea()<<endl;
cout<<t.getPerimeter()<<endl;
}

输入样例:
在这里填写一组输入
3 4

输出样例:
在这里填写相应的输出
12
12

class RTriangle:public shape {
 private:
  double height;
  double width;
 public:
  RTriangle(double a, double b){
   height = a;
   width = b;
  }
  ~RTriangle(){}
  double getArea(){
   return 0.5 * height * width;
  }
  double getPerimeter(){
   return height + width + sqrt(height * height + width * width);
  }
}; 

6.从shape类派生出一个圆形类Circle
请从下列shape类派生出一个圆形类Circle,这个类圆形的半径radius作为私有成员,类中应包含初始化半径的构造函数。圆周率PI取3.1415926。
class shape {
public:
double getArea(){ return -1; };
double getPerimeter(){ return -1 };
}

圆形类名Circle

裁判测试程序样例:
#include
using namespace std;

class shape {
public:
double getArea(){ return -1 };// 求面积
double getPerimeter(){ return -1 }; // 求周长
};

/* 你提交的代码将被嵌入到这里 */

int main() {
double r;
cin>>r;
Circle c;
cout<<c.getArea()<<endl;
cout<<c.getPerimeter()<<endl;
return 0;
}
/* 请在这里填写答案 */

输入样例:
在这里填写一组输入
2.78

输出样例:
在这里填写相应的输出
24.2795
17.4673

const double PI = 3.1415926;
class Circle:public shape {
 private:
  double r;
 public:
  Circle(double radius) {
   r = radius;
  }
  double getArea() {
    return PI * r * r;
   }
  double getPerimeter()
   {
    return 2 * PI * r;
   }
};

7.计算圆柱体的表面积(函数名隐藏)
Cylinder类是Circle类的派生类,在下面的程序中计算并输出了圆柱体的表面积。请阅读理解下面的程序。将下面的Cylinder类补充完整后提交。
Cylinder类的定义:
class Cylinder :public Circle{
double height;
public:

};

你提交的Cylinder类的定义将嵌入到下面的程序中:
#include
using namespace std;
const double PI=3.1415926;
class Circle{
protected:
double radius;
public:
Circle(double r){
radius=r;
}
double getArea(){
return PIradiusradius;
}
};
// 你提交的代码将嵌入在这里

int main()
{
double r,h;
cin>>r>>h;
Cylinder Cy1(r,h) ;
cout<<Cy1.getArea()<<endl;
return 0;
}

输入样例:
3.5 4.2

输出样例:
106.369

class Cylinder:public Circle{
  double height;  
  public:
   Cylinder(double radius,double h):Circle(radius) {
     height = h;
    }
  ~Cylinder(){}
  double getArea(){
   return PI * radius * radius * 2 + height * PI * radius * 2;
  }
};

8.狗的继承
完成两个类,一个类Animal,表示动物类,有一个成员表示年龄。一个类Dog,继承自Animal,有一个新的数据成员表示颜色,合理设计这两个类,使得测试程序可以运行并得到正确的结果。
函数接口定义:
按照要求实现类
裁判测试程序样例:
/* 请在这里填写答案 */

int main(){
Animal ani(5);
cout<<“age of ani:”<<ani.getAge()<<endl;
Dog dog(5,“black”);
cout<<“infor of dog:”<<endl;
dog.showInfor();
}

输入样例:

输出样例:
age of ani:5
infor of dog:
age:5
color:black

#include<iostream>
#include<cstring>
using namespace std;
class Animal
{
 protected:
  int age;
 public:
  Animal(int age1) {
   age = age1;
  }
  ~Animal(){}
  int getAge() {
   return age;
  }
};
class Dog:public Animal{
 private:
  char color[10];
  int age1;
 public:
  Dog(int age1, char color1[]):Animal(age1)
  {
   age = age1;
   strcpy(color, color1);
  }
  ~Dog(){};
  void showInfor()
  {
   cout << "age:" << getAge() << endl;
   cout << "color:" << color << endl;
  }
};

9.面向对象程序设计的继承性鼓励程序员重用被实践验证的高质量软件。T
10.一个类的私有成员 B

A. 只能被该类的成员函数访问
B. 只能被该类的成员函数和友元函数访问
C. 只能被该类的成员函数、友元函数和派生类访问
D. 以上答案都不对
11.在公有继承的情况下,在派生类中能够访问的基类成员包括 D

A. 公有成员
B. 保护成员
C. 公有成员、保护成员和私有成员
D. 公有成员和保护成员
12.派生类继承基类的方式有 D

A. public
B. private
C. protected
D. 以上都对
13.假设在公有派生情况下,以下说法不正确的是 A

A. 可以将基类对象复制给派生类对象
B. 可以将派生类对象的地址复制给基类指针
C. 可以将派生类对象赋值给基类的引用
D. 可以将派生类对象赋值给基类对象
14.从shape类派生出一个正六边形类RHexagon
从下列的抽象类shape类派生出一个正六边形(regular hexagon)RHexagon类。RHexagon类将正六边形的边长作为私有成员,类中包含初始化这个值的构造函数。
class shape {// 抽象类
public:
virtual double getArea()=0;// 求面积

virtual double getPerimeter()=0; // 求周长};

正六边形类名:
RHexagon

裁判测试程序样例:
#include
#include
using namespace std;

class shape {// 抽象类
public:
virtual double getArea()=0;// 求面积
virtual double getPerimeter()=0; // 求周长
};
//你提交的代码将嵌入到这里

int main()
{
double s;
cin>>s;
RHexagon p(s);
cout<<p.getArea()<<endl;
cout<<p.getPerimeter()<<endl;
}

输入样例:
16.8

输出样例:
733.281
100.8

class RHexagon:public shape {
  private :
    double length;
  public:
   RHexagon(double r):length(r){
   } 
    double getArea(){
      return 3*sqrt(3)*length*length/2;
    }
    double getPerimeter(){
      return 6*length;
    }
};

15.求平面几何形状的面积(圆形和矩形)C++
下列shape类是一个表示形状的基类,该类有一个计算形状面积的方法area( )。请以形状类"Shape"为基类派生出圆形类"Circle"和矩形类"Rectangle",要求保持求面积的接口不变。从键盘输入圆形的半径和矩形的长和宽,在主函数中创建一个圆形类"Circle"的对象和一个矩形类"Rectangle"的对象,计算并输出这个圆形和矩形的面积。圆周率PI=3.14
class shape{
public:
double area( ){ }
};

圆形类名:Circle 注意:圆周率PI=3.14
矩形类名:Rectangle

裁判测试程序样例:
#include < iostream >
using namespace std;
class Shape{
public:
double area ( ){ return -1; }
};
//你提交的代码将嵌入到这里。

int main()
{
double r,h,w;
cin>>r>>h>>w;
Circle c; Rectangle rect(h,w);
cout<<"The area of the Circle is "<<c.area( )<<endl;
cout<<"The area of the Rectangle is "<<rect.area( )<<endl;
return 0;
}

输入样例:
8.8
16.8 9.8

输出样例:
The area of the Circle is 243.162
The area of the Rectangle is 164.64

class Circle:public Shape {
 private:
  double radius;
 public:
  Circle(double r):radius(r) {
  }
  double area(){
   return 3.14 * radius * radius;
    }
}; 
class Rectangle:public Shape {
 private:
  double width;
  double length;
 public:
  Rectangle(double w, double l):width(w), length(l) {
  }
  double area(){
   return width * length;
  }
}; 

16.学生CPP成绩计算
给出下面的人员基类框架:
class Person
{
protected:
string name;
int age; public:
Person();
Person (string p_name, int p_age);
void display () {cout<<name<<“:”<<age<<endl;}};
建立一个派生类student,增加以下成员数据:
int ID;//学号
float cpp_score;//cpp上机成绩
float cpp_count;//cpp上机考勤
float cpp_grade;//cpp总评成绩
//总评成绩计算规则:cpp_grade = cpp_score * 0.9 + cpp_count * 2;增加以下成员函数:
student类的无参构造函数
student类的参数化构造函数//注意cpp_grade为上机成绩和考勤的计算结果
void print()//输出当前student的信息
//其中cpp_grade输出保留一位小数
//输出格式为ID name cpp_grade生成上述类并编写主函数,根据输入的学生基本信息,建立一个学生对象,计算其cpp总评成绩,并输出其学号、姓名、总评成绩。
输入格式: 测试输入包含若干测试用例,每个测试用例占一行(学生姓名 学号 年龄 cpp成绩 cpp考勤)。当读入0时输入结束,相应的结果不要输出。
输入样例:
Bob 10001 18 75.5 4
Mike 10005 17 95.0 5
0
输出样例:
10001 Bob 75.9
10005 Mike 95.5

#include <iostream>
#include <string.h>
#include <iomanip>
using namespace std;
class Person
{
  protected:
     string name;
     int age;
    public:
     Person(){}      
     Person (string p_name, int p_age) {
   name = p_name; 
  age = p_age;}
     ~Person(){ }
     void display () {
   cout << name << ":" << age << endl;
   }
};
class student:public Person
{   private:
     int ID;    //学号
     float cpp_score;  //cpp上机成绩
     float cpp_count; //cpp上机考勤
     float cpp_grade; //cpp总评成绩
    public: //总评成绩计算规则:cpp_grade = cpp_score * 0.9 + cpp_count * 2;
     student(){}
     student(string n,int i,int a,float p,float q):Person(n,a) {
   name = n;
   ID = i;
   age = a;
   cpp_score = p;
   cpp_count = q;
   cpp_grade = p * 0.9 + q * 2;
   }
    ~student(){}
     void print()
     {
       cout << ID << " " << name << " " << setiosflags(ios::fixed) << 
    setprecision(1) << cpp_grade << endl;
       }
};
int main() {  
 int a, i;
 string n;
 float p, q;
 while(1) {   
  cin>>n;
     if(n == "0") return 0;
     else {
      cin >> i;
      cin >> a;
      cin >> p;
      cin >> q;
      student s(n, i, a, p, q); 
      s.print();
    }
}
 return 0;  
}

17.在C++语言中设置虚基类的目的是( C ) 。

A. 简化程序代码
B. 提高程序的运行效率
C. 解决多继承造成的二义性问题
D. 缩短程序的目标代码

18.下列关于继承的描述中,错误的是( D )。

A. 析构函数不能被继承
B. 派生类是基类的组合
C. 派生类的成员除了它自己的成员外,还包含了它的基类的成员
D. 派生类中继承的基类成员的访问权限到派生类保持不变

19.In a(n) is-a relationship, an object of a derived class also can be treated as an object of its base class.

20.A base class’s protected members can be accessed only in the base-class definition or in derived-class definitions.

21.写出派生类构造方法(C++)
裁判测试程序样例中展示的是一段定义基类People、派生类Student以及测试两个类的相关C++代码,其中缺失了部分代码,请补充完整,以保证测试程序正常运行。
函数接口定义:
提示:
观察类的定义和main方法中的测试代码,补全缺失的代码。

裁判测试程序样例:
注意:真正的测试程序中使用的数据可能与样例测试程序中不同,但仅按照样例中的格式调用相关函数。
#include
using namespace std;
class People{
private:
string id;
string name;
public:
People(string id, string name){
this->id = id;
this->name = name;
}
string getId(){
return this->id;
}
string getName(){
return name;
}
};
class Student : public People{
private:
string sid;
int score;
public:
Student(string id, string name, string sid, int score)
/** 你提交的代码将被嵌在这里(替换此行) **/
}
friend ostream& operator <<(ostream &o, Student &s);
};
ostream& operator <<(ostream &o, Student &s){
o << “(Name:” << s.getName() << “; id:”
<< s.getId() << “; sid:” << s.sid
<< “; score:” << s.score << “)”;
return o;
}
int main(){
Student zs(“370202X”, “Zhang San”, “1052102”, 96);
cout << zs << endl;
return 0;
}

输入样例:
(无)

输出样例:
(Name:Zhang San; id:370202X; sid:1052102; score:96)

:People(id,name),sid(sid),score(score){

22.7-1 日程安排(多重继承+重载) (12 分)已有一个日期类Date,包括三个protected成员数据
int year;
int month;
int day;
另有一个时间类Time,包括三个protected成员数据
int hour;
int minute;
int second;
现需根据输入的日程的日期时间,安排前后顺序,为此以Date类和Time类为基类,建立一个日程类Schedule,包括以下新增成员:
int ID;//日程的ID
bool operator < (const Schedule & s2);//判断当前日程时间是否早于s2
生成以上类,并编写主函数,根据输入的各项日程信息,建立日程对象,找出需要最早安排的日程,并输出该日程对象的信息。
输入格式: 测试输入包含若干日程,每个日程占一行(日程编号ID 日程日期(**//)日程时间(::))。当读入0时输入结束,相应的结果不要输出。
输入样例:
1 2014/06/27 08:00:01
2 2014/06/28 08:00:01
0
输出样例:
The urgent schedule is No.1: 2014/6/27 8:0:1

#include <iostream>
#include <cstdlib>
#include <cstdio>
using namespace std;
class Date {
 protected:
     int year;
     int month;
     int day;
 public:
     Date(int _y, int _m, int _d):year(_y), month(_m), day(_d){}
};
class Time {
 protected:
     int hour;
     int minute;
     int second;
 public:
     Time(int _h, int _m, int _s):hour(_h), minute(_m), second(_s){}
};
class Schedule:public Date, public Time {
 private:
     int ID;
 public:
     Schedule():Date(0,0,0), Time(0,0,0), ID(0){}
     Schedule(int _id, int _year, int _month, int _day, int _hour, int _minute, int _second):Date(_year, _month, _day), Time(_hour, _minute, _second), ID(_id){}
     bool operator < (const Schedule &s) {
         char timeArr1[15], timeArr2[15];
         sprintf(timeArr1, "%04d%02d%02d%02d%02d%02d", year, month, day, hour, minute, second);
         sprintf(timeArr2, "%04d%02d%02d%02d%02d%02d", s.year, s.month, s.day, s.hour, s.minute, s.second);
         return atof(timeArr1) < atof(timeArr2);
    }
    void show() {
        cout << "The urgent schedule is No."<<ID<<": "<<year<<"/"<<month<<"/"<<day<<" "<<hour<<":"<<minute<<":"<<second<<endl;
    }
};
int main() {
    int id, rows = 0;
    int y, m, d, h, i, s;
    Schedule min;
    while (cin >> id) {
        if(id == 0) break;
        scanf("%d/%d/%d %d:%d:%d", &y, &m, &d, &h, &i, &s);
        Schedule cur(id, y, m, d, h, i, s);
        if(rows++ == 0) min = cur;
        if(cur < min) min = cur;
    }
    if(rows != 0) min.show();
    return 0;
}

第六章 运算符重载

1.对每个可重载的运算符来讲,它既可以重载为友元函数,又可以重载为成员函数,还可以重载为非成员函数。F
2.对单目运算符重载为友元函数时,可以说明一个形参。而重载为成员函数时,不能显式说明形参。T
3.重载operator+时,返回值的类型应当与形参类型一致。
比如以下程序中,operator+的返回值类型有错:F

class A {
	int x;
 public:
 	A(int t=0):x(t){	 }
    int operator+(const A& a1){ return x+a1.x;  }};

4.In C++, only existing operators can be overloaded. T
5.下列运算符中,(C )运算符不能重载。

A. &&
B. [ ]
C. ::
D. <<
6.下列关于运算符重载的描述中,(D )是正确的。

A. 运算符重载可以改变操作数的个数
B. 运算符重载可以改变优先级
C. 运算符重载可以改变结合性
D. 运算符重载不可以改变语法结构

7.使用成员函数重载复数类的运算符+
类Complex声明了一个复数类,有两个数据成员realPart(代表复数的实部)和imgPart(代表复数的虚部),并定义了成员函数实现了重载运算符“+”以实现两个复数对象的相加操作。成员函数Show用来输出复数的实部和虚部。请完成对运算符“+”的重载操作。
函数接口定义:
Complex& Complex::operator+(Complex& com);

参数com为复数类Complex的对象的引用,函数的返回值为当前对象与com对象相加后的值。
裁判测试程序样例:
#include
using namespace std;

class Complex {
public:
Complex(double realPart = 0, double imgPart = 0) {
this->realPart = realPart;
this->imgPart = imgPart;
}
Complex& operator+(Complex& com);
void Show() {
cout << realPart << " " << imgPart << endl;
}
private:
double realPart, imgPart;
};
int main() {
int r1, i1; //第1个复数对象的实部和虚部
int r2, i2; //第1个复数对象的实部和虚部
cin >> r1 >> i1;
cin >> r2 >> i2;
Complex c1(r1, i1); //构造第1个复数对象c1
Complex c2(r2, i2); //构造第2个复数对象c2
c1 = c1 + c2;
c1.Show();
return 0;
}
/* 你的代码将被嵌在这里 */

输入样例:
3 4
10 20

输出样例:
13 24

Complex  &Complex :: operator+(Complex& com) {
    realPart += com.realPart;
    imgPart += com.imgPart;
    return *this;
}

8.单目运算符重载(时钟类)
本题已给出时钟类及其成员函数实现,要求补充完整运算符++重载函数(前置和后置),使之能够实现时钟对象自增1秒。
时钟类定义如下:
class Clock {
public:
Clock(int NewH=0, int NewM=0, int NewS=0);
void ShowTime();
friend Clock operator++(Clock& op); //前置单目运算符重载
friend Clock operator++(Clock& op,int); //后置单目运算符重载
private:
int Hour, Minute, Second;
};

裁判测试程序样例:
#include
using namespace std;

class Clock {
public:
Clock(int NewH=0, int NewM=0, int NewS=0);
void ShowTime();
friend Clock operator++(Clock& op); //前置单目运算符重载
friend Clock operator++(Clock& op,int); //后置单目运算符重载
private:
int Hour, Minute, Second;
};

Clock::Clock(int NewH, int NewM, int NewS) {
Hour=NewH;
Minute=NewM;
Second=NewS;
}
void Clock::ShowTime() {
cout<<Hour<<":"<<Minute<<":"<<Second<<endl;
}

/---------请在这里填写答案-----------/

int main() {
int h, m, s;
cin>>h>>m>>s;
Clock a(h,m,s);
(++a).ShowTime();
(a++).ShowTime();
a.ShowTime();
return 0;
}

输入样例:
在这里给出一组输入。例如:
10 10 10

输出样例:
在这里给出相应的输出。例如:
10:10:11
10:10:11
10:10:12

Clock operator ++(Clock &op) {
    op.Second++;
    if (op.Second >= 60) {
        op.Second = op.Second - 60;
        op.Minute++;
        if (op.Minute >= 60) {
            op.Minute = op.Minute - 60;
            op.Hour++;
            op.Hour = op.Hour % 24;
        }
    }
    return op;
}
Clock operator ++(Clock &op, int) {
    Clock OP = op;
    op.Second++;
    if (op.Second >= 60) {
        op.Second = op.Second - 60;
        op.Minute++;
        if (op.Minute >= 60) {
            op.Minute = op.Minute - 60;
            op.Hour++;
            op.Hour = op.Hour % 24;
        }
    }
    return OP;
}

9.多数运算符可以重载,个别运算符不能重载,运算符重载是通过函数定义实现的。T
10.为了能出现在赋值表达式的左右两边,重载的"[]"运算符应定义为: B

A. A operator [ ] (int);
B. A& operator [ ] (int);
C. const A operator [ ] (int);
D. 以上答案都不对

11.在C++中不能重载的运算符是 A

A. ?:
B. +
C. -
D. <=

12.对学生对象按照成绩升序排序
下面这段代码要实现对学生对象按照成绩升序排序。
仔细阅读代码,要求实现编程实现输出运算符“<<”和小于“<”运算符,使本程序能完成预定的排序功能。
裁判测试程序样例:
#include
#include
#include
using namespace std;

class Student {
string name;
char sex;
int score;
string grade;

public:
Student(string name, char sex, int score, string grade);
friend ostream &operator<< (ostream& os, Student st) ;
friend bool operator<(Student &st1, Student &st2);
};
//你提交的代码将被嵌入到这里

Student::Student(string name, char sex, int score, string grade) {
this->name = name;
this->sex = sex;
this->score = score;
this->grade = grade;
}

int main() {
list st;
string name, grade;
char sex; int score;

for(int i = 0; i < 5; i++) {
cin>>name; cin>>sex;
cin>>score; cin>>grade;
st.push_back(Student(name, sex, score, grade));
}

st.sort();

list::iterator p = st.begin();
while(p != st.end()) {
cout<<*p;
p++;
}
return 0;
}

输入样例:
Bill M 86 JK1501
David M 98 JK1502
Mary F 78 JK1503
Adam M 83 JK1504
Rose F 96 JK1505

输出样例:
Mary F 78 JK1503
Adam M 83 JK1504
Bill M 86 JK1501
Rose F 96 JK1505
David M 98 JK1502

ostream &operator<< (ostream& os, Student st) {
    os << st.name << " " << st.sex << " " << st.score << " " << st.grade << endl;
}
bool operator<(Student &st1, Student &st2) {
    if(st1.score < st2.score) {
        return true;
    } else {
        return false;
    }
}

13.重载下标运算符[ ]
这段程序实现了安全数组。
请认真阅读程序并补全程序使之能正确执行。
裁判测试程序样例:
在这里给出函数被调用进行测试的例子。例如:
#include
#include
using namespace std;
const int SIZE = 3;

class atype {
int a[SIZE];
public:
atype( ) {
register int i;
for(i=0; i<SIZE; i++) a[i] = i;
}
int &operator[](int i);
};
//你提交的代码将被嵌入到这里

int main( )
{
atype ob;
cin >> ob[1];
ob[2] = ob[1]; // 下标运算符[]出现在赋值运算符的左边和右边
cout << ob[2];
ob[3] = 44; // 产生运行时错误,下标3超出了数组边界
return 0;
}

输入样例:
98

输出样例:
98
Index value of 3 is out-of-bounds.

int &atype :: operator[](int i) {
    if (i < 0 || i > SIZE) {
        cout << endl;
        cout << "Index value of 3 is out-of-bounds.";
        exit(0);
    }
    return a[i];
}

14.复数类重载加法、减法和乘法运算符
以下定义了一个复数类及其部分实现,现要求将类的构造函数以及运算符+、- 和 * 函数重载补充完整。
复数类定义:
在这里描述复数类定义。具体如下:
class complex {
public:
complex(float r=0,float i=0); // 构造函数
complex operator+(const complex &op2) const; //重载运算符 +
complex operator-(const complex &op2) const; //重载运算符 -
complex operator*(const complex &op2) const; //重载运算符 *
void display() const; // 按数学写法输出复数
private:
float real;
float imag;
};

裁判测试程序样例:
在这里给出复数类测试的例子。例如:
#include
using namespace std;
class complex {
public:
complex(float r=0,float i=0); // 构造函数
complex operator+(const complex &op2) const; //重载运算符 +
complex operator-(const complex &op2) const; //重载运算符 -
complex operator*(const complex &op2) const; //重载运算符 *
void display() const; // 按数学写法输出复数
private:
float real;
float imag;
};

/* ------------------- 请在这里填写答案-------------------- */

void complex::display() const {
if(real&&imag)
if(imag == 1 || imag == -1)
cout<<real<<(imag>0?"+":"-")<<“i”<<endl;
else
cout<<real<<(imag>0?"+":"")<<imag<<“i”<<endl;
else if(real)
cout<<real<<endl;
else if (imag)
if(imag == 1||imag == -1)
cout<<(imag>0?"":"-")<<“i”<<endl;
else
cout<<imag<<“i”<<endl;
else
cout<<0<<endl;
}

int main() {
double real,imag;
complex c,d,e;
cin>>real>>imag;
complex c1(real,imag);
cin>>real>>imag;
complex c2(real,imag);
c=c1+c2;
d=c1-c2;
e=c1*c2;
c.display() ;
d.display() ;
e.display();
return 0;
}

输入样例:
在这里给出一组输入。例如:
2 3
-4 -5

输出样例:
在这里给出相应的输出。例如:
-2-2i
6+8i
7-22i

complex :: complex(float r, float i) {
    real = r;
    imag = i;
}
complex  complex :: operator+(const complex &op2) const {
    complex Complex;
    Complex.real = op2.real + real;
    Complex.imag = op2.imag + imag;
    return Complex;
}
complex  complex :: operator-(const complex &op2) const {
    complex Complex;
    Complex.real = real - op2.real ;
    Complex.imag =  imag - op2.imag;
    return Complex;
}
complex  complex :: operator*(const complex &op2) const {
    complex Complex;
    Complex.real = real * op2.real - imag * op2.imag;
    Complex.imag =  imag * op2.real + real * op2.imag;
    return Complex;
}

第七章 多态性和虚函数

1.虚函数是用virtual 关键字说明的成员函数。 T
2.动态绑定是在运行时选定调用的成员函数的。 T
3.构造函数可以声明为虚函数。F
4.构造函数可以声明为纯虚函数。F
5.虚函数不能是类的静态成员。T
6.重定义虚函数的派生类必须是公有继承的。T
7.作为虚函数隐含参数的this指针,决定了虚函数调用时执行的代码。T

8.关于纯虚函数和抽象类的描述中,(C )是错误的。

A. 纯虚函数是一种特殊的虚函数,它没有具体的实现
B. 抽象类是指具有纯虚函数的类
C. 一个基类中说明有纯虚函数,该基类的派生类一定不再是抽象类
D. 抽象类只能作为基类来使用,其纯虚函数的实现由派生类给出

9.虚析构函数的作用是。 C

A. 虚基类必须定义虚析构函数
B. 类对象作用域结束时释放资源
C. delete动态对象时释放资源
D. 无意义

10.在派生类中,重载一个虚函数时,要求函数名、参数的个数、参数的类型、参数的顺序和函数的返回值。 A

A. 相同
B. 不同
C. 相容
D. 部分相同

11.若一个类中含有纯虚函数,则该类称为。 C

A. 基类
B. 纯基类
C. 抽象类
D. 派生类

12.假设 Aclass为抽象类,下列正确的说明语句是。 B

A. Aclass fun( int ) ;
B. Aclass * p ;
C. int fun( Aclass ) ;
D. Aclass Obj ;

13.关于动态绑定的下列描述中,(D )是错误的。

A. 动态绑定是以虚函数为基础的
B. 动态绑定在运行时确定所调用的函数代码
C. 动态绑定调用函数操作是通过指向对象的指针或对象引用来实现的
D. 动态绑定是在编译时确定操作函数的

14.汽车收费
现在要开发一个系统,管理对多种汽车的收费工作。
给出下面的一个基类框架
class Vehicle
{
protected:
string NO;public:
Vehicle(string n){
NO = n;
}
virtual int fee()=0;//计算应收费用
};
以Vehicle为基类,构建出Car、Truck和Bus三个类。
Car的收费公式为: 载客数8+重量2
Truck的收费公式为:重量5
Bus的收费公式为: 载客数
3
生成上述类并编写主函数
主函数根据输入的信息,相应建立Car,Truck或Bus类对象,对于Car给出载客数和重量,Truck给出重量,Bus给出载客数。假设载客数和重量均为整数
输入格式:第一行输入测试用例数。接着每个测试用例占一行,每行给出汽车的基本信息,第一个数据为当前汽车的类型:1为car,2为Truck,3为Bus。第二个数据为它的编号,接下来Car是载客数和重量,Truck要求输入重量,Bus要求输入载客数。
要求输出各车的编号和收费。
裁判测试程序样例:
#include
#include
using namespace std;
class Vehicle
{
protected:
string NO;//编号
public:
Vehicle(string n){ NO = n; }
virtual int fee()=0;//计算应收费用
};

/* 请在这里填写答案 */

int main()
{
Car c("",0,0);
Truck t("",0);
Bus b("",0);
int i, repeat, ty, weight, guest;
string no;
cin>>repeat;
for(i=0;i<repeat;i++){
cin>>ty>>no;
switch(ty){
case 1: cin>>guest>>weight; c=Car(no, guest, weight); cout<<no<<’ ‘<<c.fee()<<endl; break;
case 2: cin>>weight; t=Truck(no, weight); cout<<no<<’ ‘<<t.fee()<<endl; break;
case 3: cin>>guest; b=Bus(no, guest); cout<<no<<’ '<<b.fee()<<endl; break;
}
}
return 0;
}

输入样例:
4
1 002 20 5
3 009 30
2 003 50
1 010 17 6

输出样例:
002 170
009 90
003 250
010 148

class Car:public Vehicle{
public:
    int guest;
    int weight;
    Car(string Number,int g,int w):Vehicle(Number){
        guest = g;
        weight = w;
    }
    int fee(){
        return guest*8+weight*2;
    }
};
class Truck:public Vehicle{
public:
    int weight;
    Truck(string Number,int w):Vehicle(Number){
        weight = w;
    }
    int fee(){
        return weight * 5;
    }
};
class Bus:public Vehicle{
public:
    int guest;
    Bus(string Number,int g):Vehicle(Number){
        guest = g;
    }
    int fee(){
        return guest * 3;
    }
};

15.抽象类Shape
请编写一个抽象类Shape,包括两个纯虚函数,分别为计算面积getArea()和计算周长getPerim()。通过Shape类派生出矩形类Rectangle和圆类Circle,并计算各自的面积和周长。
测试用例具体要求:输入1表示测试矩形类,之后输入矩形长和宽。输入2表示测试圆类,之后输入圆半径。
Shape类定义如下:
class Shape {
public:
virtual double getArea()=0;
virtual double getPerim()=0;
};

裁判测试程序样例:
#include
using namespace std;
const double PI=3.14;

class Shape {
public:
virtual double getArea()=0;
virtual double getPerim()=0;
};

/* ------请在这里填写答案 ------*/

int main() {
Shape *p;
int n;
double w,h,r;
scanf("%d",&n);
switch(n) {
case 1: {
cin>>w>>h;
Rectangle rect(w,h);
cout<<“area=”<<rect.getArea()<<endl;
cout<<“perim=”<<rect.getPerim()<<endl;
break;
}
case 2: {
cin>>r;
Circle c;
cout<<“area=”<<c.getArea()<<endl;
cout<<“perim=”<<c.getPerim()<<endl;
break;
}
}
return 0;
}

输入样例1:
在这里给出一组输入。例如:
1
4 5

输出样例1:
在这里给出相应的输出。例如:
area=20
perim=18

输入样例2:
在这里给出一组输入。例如:
2
5

输出样例2:
在这里给出相应的输出。例如:
area=78.5
perim=31.4

class Rectangle : public Shape{
private:
    double width;
    double height;
public:
    Rectangle(double w, double h){
        width = w;
        height = h;
    }
    double getArea(){
        return width * height;
    }
    double getPerim(){
        return (width + height) * 2;
    }
};
class Circle : public Shape{
private:
    double radius;
public:
    Circle(double r){
        radius = r;
    }
    double getArea(){
        return PI * radius * radius;
    }
    double getPerim(){
        return (PI * radius) * 2;
    }
};

16.虚函数的应用
补充下列代码,使得程序的输出为:

A:3

A:15

B:5

3

15

5
类和函数接口定义:
参见裁判测试程序样例中的类和函数接口。

裁判测试程序样例:
#include
using namespace std;
class CMyClassA {
int val;
public:
CMyClassA(int);
void virtual print();
};
CMyClassA::CMyClassA(int arg) {
val = arg;
printf(“A:%d\n”, val);
}
void CMyClassA::print() {
printf("%d\n", val);
return;
}

/* 在这里填写代码 */

int main(int argc, char** argv) {
CMyClassA a(3), *ptr;
CMyClassB b(5);
ptr = &a;
ptr->print();
a = b;
a.print();
ptr = &b;
ptr->print();
return 0;
}

输入样例:
None

输出样例:
A:3
A:15
B:5
3
15
5

来源:
openjudge.cn

class CMyClassB :public CMyClassA {
  public:
      int val2;
    CMyClassB(int x) :CMyClassA(3 * x), val2(x) {
        printf("B:%d\n", val2);
    }
    void print() {
        printf("%d\n", val2);
    }
};

17.关于虚函数的描述中,(C )是正确的。

A. 虚函数是一个static 类型的成员函数
B. 虚函数是一个非成员函数
C. 基类中说明了虚函数后,派生类中与其对应的函数可不必说明为虚函数
D. 派生类的虚函数与基类的虚函数具有不同的参数个数和类型

18.阅读下列说明和C++代码,将应填入 (n) 处的字句写在答题纸的对应栏内。
【说明】现欲构造一文件/目录树,采用组合(Composite)设计模式来设计,得到的类图如下所示
在这里插入图片描述
【C++代码】

#include
#include
#include
using namespace std;

class AbstractFile {
protected :
string name; // 文件或目录名称
public:
void printName(){cout << name;} // 打印文件或目录名称
virtual void addChild(AbstractFile * file)=0; // 给一个目录增加子目录或文件
virtual void removeChild(AbstractFile * file)=0;// 删除一个目录的子目录或文件
virtual list<AbstractFile* > * getChildren()=0;// 获得一个目录的子目录或文件
};
class File : public AbstractFile {
public :
File(string name) { this -> name(2分) = name; }
void addChild(AbstractFile * file) { return ; }
void removeChild(AbstractFile * file) { return ; }
list <AbstractFile*>* (2分) getChildren() { return NULL(2分); }
};
class Folder :public AbstractFile {
private :
list <AbstractFile*> childList; // 存储子目录或文件
public :
Folder(string name) { this -> name(2分)= name; }
void addChild(AbstractFile *file) { childList.push_back(file); }
void removeChild(AbstractFile file) { childList.remove(file);}
list<AbstractFile
> *getChildren() { return NULL(2分) ; }
};

int main( ) {
// 构造一个树形的文件/目录结构
AbstractFile *rootFolder = new Folder(“c:\”);
AbstractFile *compositeFolder = new Folder(“composite”);
AbstractFile *windowsFolder = new Folder(“windows”);
AbstractFile *file = new File(“TestComposite.java”);
rootFolder->addChild(compositeFolder);
rootFolder->addChild(windowsFolder);
compositeFolder->addChild(file);
return 0;
}

19.从抽象类shape类派生出一个正五边形类(C++)
从下列的抽象类shape类派生出一个正五边形(regular pentagon)类RPentagon,这个类将正五边形的边长作为私有成员,类中包含初始化这个值的构造函数。
class shape {// 抽象类
public:
virtual double getArea()=0;// 求面积

virtual double getPerimeter()=0; // 求周长};

正五边形类名:
RPentagon

裁判测试程序样例:
#include
#include
using namespace std;

class shape {// 抽象类
public:
virtual double getArea()=0;// 求面积
virtual double getPerimeter()=0; // 求周长
};
//你提交的代码将嵌入到这里

int main()
{
double s;
cin>>s;
RPentagon p(s);
cout<<p.getArea()<<endl;
cout<<p.getPerimeter()<<endl;
}

输入样例:
16.8

输出样例:
485.5875
84

class RPentagon : public shape {
public:
    double a;
    RPentagon(double s){
        a = s;
    }
    double getArea() {
        return a * a * sqrt(25 + 10 * sqrt(5)) / 4.0;
    }
    double getPerimeter () {
        return a *5;
    }
};

20.从shape类派生出一个直角三角形类RTriangle
从shape类派生出一个直角三角形类RTriangle类(regular triangle)。两条直角边长作为RTriangle类的私有成员,类中包含参数为直角边的构造方法。
class shape {// 抽象类
public:
virtual double getArea()=0;// 求面积

virtual double getPerimeter()=0; // 求周长};
直角三角形类名:RTriangle
直角三角形类的构造函数原型如下:
RTriangle(double a, double b);
其中 a 和 b 都是直角三角形的两条直角边。
裁判测试程序样例:
#include
#include
using namespace std;

class shape {// 抽象类
public:
virtual double getArea()=0;// 求面积
virtual double getPerimeter()=0; // 求周长
};
//你提交的代码将嵌入到这里

int main()
{
double a,b;
cin>>a>>b;
RTriangle t(a,b);
cout<<t.getArea()<<endl;
cout<<t.getPerimeter()<<endl;
}

输入样例:
在这里填写一组输入
3 4

输出样例:
在这里填写相应的输出
12
12

class RTriangle:public shape{
private:
    double a;
    double b;
public:
    RTriangle(double a1,double b1) {
        a = a1;
        b = b1;
    }
    double getArea() {
        return 0.5 * a * b;
    }
    double getPerimeter() {
        return a + b + sqrt(a * a + b * b);
    }
};

第八章 模板

1.关于函数模板,描述错误的是。 A

A. 函数模板必须由程序员实例化为可执行的函数模板
B. 函数模板的实例化由编译器实现
C. 一个类定义中,只要有一个函数模板,则这个类是类模板
D. 类模板的成员函数都是函数模板,类模板实例化后,成员函数也随之实例化

2.下列的模板说明中,正确的是。 C

A. template < typename T1, T2 >
B. template < class T1, T2 >
C. template < typename T1, typename T2 >
D. template ( typedef T1, typedef T2 )

3.假设有函数模板定义如下:

template Max( T a, T b ,T &c)
{ c = a + b ; }

下列选项正确的是( B )。

A. int x, y; char z ;Max( x, y, z ) ;
B. double x, y, z ;Max( x, y, z ) ;
C. int x, y; float z ;Max( x, y, z );
D. float x; double y, z;Max( x, y, z ) ;

4.建立类模板对象的实例化过程为。 C

A. 基类-派生类
B. 构造函数-对象
C. 模板类-对象
D. 模板类-模板函数

5.一个简单的队列类模板
请按照下列简单的整数队列类创建一个简单的队列类模板。
整数队列类如下:
const int SIZE=100;
//整数队列类
class Queue {
int q[SIZE];
int front; //队列头
int rear; //队列尾
public:
Queue( )
{ front = rear = 0; }
void put(int i); // 在队尾放置一个数据
int get( ); // 从队列头部取一个数据
};

裁判测试程序样例:
在这里给出函数被调用进行测试的例子。例如:
#include
#include
using namespace std;
// 你提交的代码将嵌入到这里

int main()
{
Queue a; // 创建一个整数队列
int m,n;
cin>>m>>n;
a.put(m);
a.put(n);
cout << a.get() << " ";
cout << a.get() << endl;

Queue d; // 创建一个双精度浮点数队列
double x,y;
cin>>x>>y;
d.put(x);
d.put(y);
cout << d.get() << " ";
cout << d.get() << endl;

Queue qs;// 创建一个字符串队列
string s1,s2,s3;
cin>>s1>>s2>>s3;
qs.put(s1);
qs.put(s2);
qs.put(s3);
cout << qs.get() << " ";
cout << qs.get() << " ";
cout << qs.get() << endl;

return 0;
}

输入样例:
6 9
3.14159 2.781828
ShenZhen Beijing HangZhou

输出样例:
6 9
3.14159 2.78183
ShenZhen Beijing HangZhou

const int SIZE = 100;
template <typename T> class Queue {
private:
    T q[SIZE];
    int front;
    int rear;
public:
    Queue() {
        front = rear = 0;
    }
    void put(T i);
    T get();
};
template <class T> void Queue<T> :: put(T i) {
    if (front == SIZE)
        exit(0);
    rear++;
    q[rear] = i;
}
template <class T>T Queue<T> :: get() {
    if (rear == front)
        return 0;
    front++;
    return q[front];
}

6.Max函数模板
创建一个函数模板Max( ),该模板返回两个参数中的最大值,例如:

Max(3,4)返回4
Max(‘c’,‘a’)返回’c’

裁判测试程序样例:
#include
#include
using namespace std;
//你提交的代码将被嵌入到这里

int main( )
{
int m,n;
char c,d;
string s1,s2;
cin>>m>>n;
cin>>c>>d;
cin>>s1>>s2;
cout<<Max(m,n)<<endl;
cout<<Max(c,d)<<endl;
cout<<Max(s1,s2)<<endl;
return 0 ;
}

/* 请在这里填写答案 */

输入样例:
在这里填写一组输入
-21252 3

输出样例:
在这里填写相应的输出
3

template<class T> T Max(T x, T y) {
    return x > y ? x : y;
}

7.创建函数模板实现求数组中的最小元素
创建一个函数模板实现求数组中的最小元素,在主函数将分别使用该模板求整形数组和double型数组中的最小元素并输出。
输入:
6 (整型数组中的元素个数)
8 3 4 1 6 9 (整型数组中的元素)
5 (双精度浮点数数组中的元素个数)
2.7 3.1 9.8 5.3 7.6 (双精度浮点数数组中的元素)
输出:
1
2.7
函数模板接口定义:
T Min(T *p, int len)

其中 p 和 len 都是用户传入的参数。 p 是数组元素的起始地址; len 是数组的长度。
裁判测试程序样例:
#include
using namespace std;
// 你提交的代码将嵌入到这里

int main( )
{
int n,m,*pn,i=0;
cin>>n;
pn=new int[n];
do{
cin>>pn[i];
i++;
}while(i<n);
double *pd;
i=0;
cin>>m;
pd=new double[m];
do{
cin>>pd[i];
i++;
}while(i<m);
cout<<Min(pn,n)<<endl;
cout<<Min(pd,m)<<endl;
delete [ ] pn;
delete [ ] pd;
return 0;
}

输入样例:
9
8 2 7 6 4 5 3 1 0
7
3.1 9.6 5.8 2.7 6.3 7.0 8.5

输出样例:
0
2.7

emplate<class T1, class T2> T1 Min(T1 *p, T2 len) {
    int j;
    T1 min = p[0];
    for (j = 0; j < len; j++) {
        if (p[j] < min)
            min = p[j];
    }
    return min;
}

8.关于类模板,描述错误的是。 A

A. 一个普通基类不能派生类模板
B. 类模板可以从普通类派生,也可以从类模板派生
C. 根据建立对象时的实际数据类型,编译器把类模板实例化为模板类
D. 函数的类模板参数需生成模板类并通过构造函数实例化

9.下列有关模板的描述,错误的是_D___。

A. 模板把数据类型作为一个设计参数,称为参数化程序设计
B. 使用时,模板参数与函数参数相同,是按位置而不是名称对应的
C. 模板参数表中可以有类型参数和非类型参数
D. 类模板与模板类是同一个概念

10.编写一个函数模板Swap,实现两个变量交换。
编写一个函数模板Swap,实现两个变量交换。
函数模板实例化:
Swap( i, j );

:其中 i 和 j 都是用户传入的参数, i 和 j类型相同,但可以是任何数据类型。
裁判测试程序样例:
#include
using namespace std;
//你提交的代码将被嵌入到这里

int main()
{
int i,j;
char m,n;
cin>>i>>j;
cin>>m>>n;
Swap(i,j);
Swap(m,n);
cout<<i<<’ ‘<<j<<’\n’;
cout<<m <<’ '<<n<<endl;
return 0;
}

输入样例:
2 1
a c

输出样例:
1 2
c a

template <class T> void Swap(T &a, T &b) {
    T t;
    t = a;
    a = b;
    b = t;
}

11.编写一个函数模板 sort 实现选择法排序的功能
编写一个函数模板 sort 实现选择法排序的功能。
函数模板实例化:
Mysort(a,m);

其中 a 和 n 都是用户传入的参数。 a 表示数组名; m 表示数组元素的个数。
裁判测试程序样例:
#include
using namespace std;
//你提交的代码将被嵌入到这里

int main()
{
int m,n,a[20],i,j;
float b[20];
cin>>m;
for(i=0;i<m;i++)
cin>>a[i];
cin>>n;
for(j=0;j<n;j++)
cin>>b[j];
Mysort(a,m);
Mysort(b,n);
for(i=0;i<m;i++)
cout<<a[i]<<’ ‘;
cout<<endl;
for(j=0;j<n;j++)
cout<<b[j]<<’ ';
cout<<endl;
return 0;
}

输入样例:
在这里填写一组输入
6
1 4 2 6 3 5
5
1.5 1.2 1.1 1.3 1.4

输出样例:
在这里填写相应的输出
1 2 3 4 5 6
1.1 1.2 1.3 1.4 1.5

template <class T> void Mysort(T a[], int n) {
    T t;
    int i, j, k;
    for (i = 0; i < n; i++) {
        k = i;
        for(j = i + 1; j < n; j++){
            if (a[k] > a[j])
                k = j;
        }
        if (k != i) {
            t = a[i];
            a[i] = a[k];
            a[k] = t;
        }
    }
}
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/Lereno/article/details/94017535

智能推荐

Java中使用FFmpeg进行视频图像的人脸检测_java 视频识别人-程序员宅基地

文章浏览阅读106次。在Java中,我们可以使用FFmpeg库来进行视频图像的处理和分析。其中一个常见的应用是人脸检测,通过识别视频中的人脸,我们可以进行人脸识别、情感分析等各种应用。总结起来,本文介绍了如何在Java中使用FFmpeg进行视频图像的人脸检测。通过使用外部进程和FFmpeg命令,我们可以方便地在Java应用程序中集成人脸检测功能。安装和配置FFmpeg的详细步骤超出了本文的范围,您可以在FFmpeg的官方网站上找到相关的文档和指南。然后,我们构建了一个FFmpeg的命令字符串,该命令使用了FFmpeg的。_java 视频识别人

时差问题-程序员宅基地

文章浏览阅读567次。Problem4:时差问题。一个地方和北京相差17个小时(比北京慢17h),输入北京时间,输出当地时间;输入格式:年 月 日 时 分,输出格式一样。此题注意输出格式控制(后四项数字位数为两位)#include &lt;iostream&gt;#include &lt;iomanip&gt;using namespace std;bool isLeap(int year);...

【车间调度】基于matlab樽海鞘算法求解带小车的车间调度AGV-fjsp问题【含Matlab源码 3283期】-程序员宅基地

文章浏览阅读62次。樽海鞘算法求解带小车的车间调度AGV-fjsp问题完整的代码,方可运行;可提供运行操作视频!适合小白!

ccxprocess启动项可以禁用么_苹果Mac的Adobe无用自启项怎么禁用-程序员宅基地

文章浏览阅读2.5k次。在Mac上面安装过Adobe软件的用户相信都知道软件自带了不少无用自启动项呢!很对用户们都想要将自己的无用的自启动项目禁止一下呢!那么,你知道苹果Mac的Adobe无用自启项怎么禁用吗?想要详细去了解Adobe无用自启项禁用方法教程么?快来阅读下面的文章吧!最详细的答案就在这里!苹果Mac的Adobe无用自启项怎么禁用一:通过以下路径找到有关“Adobe”的文件并且删除。该锋友表示,这些启动项大部..._ccxprocess是什么启动项

操作系统——银行家算法(c++实现)_银行家算法c++代码-程序员宅基地

文章浏览阅读291次。编写银行家算法程序,能够对进程提出的资源请求进行判断,并打印出计算得到的安全序列。目的:利用银行家算法实现系统资源的动态分配及进程安全状态检测问题。_银行家算法c++代码

基于神经网络的变压器故障分类诊断_基于bp神经网络的变压器故障诊断-程序员宅基地

文章浏览阅读4.8k次,点赞2次,收藏58次。引言本文基于BP神经网络对变压器的故障进行分类和诊断。变压器根据五种特征气体对应四种故障类型(高能放电、低能放电、过热和正常)。对已知类型的训练样本进行计算,构造BP神经网络,然后对测试样本进行分类。该方法的正确率可达88%。变压器是电力系统中分布广泛、造价昂贵、结构复杂的电气设备,担负着电能传送和电压转换的重任,其正常运行直接影响了整个电力系统的安全性和稳定性。对油浸式变压器来说,随着运行的持续,油与中间的固体有机材料会逐渐老化和分解,由于不同的故障类型,产生的气体含量和比例也不同,所以可利用对油中气_基于bp神经网络的变压器故障诊断

随便推点

markdown合并单元格、设置单元格背景颜色和字体颜色_markdown表格颜色-程序员宅基地

文章浏览阅读2.6k次。markdown 编辑器通过HTML实现:设置单元格背景颜色、设置字体颜色和合并单元格的两种方式_markdown表格颜色

【Halcon轮廓提取】-程序员宅基地

文章浏览阅读1.6w次,点赞13次,收藏137次。edges_image算子:edges_image(Image : ImaAmp, ImaDir : Filter, Alpha, NMS, Low, High : )功能:使用Deriche, Lanser, Shen或者Canny 滤波器进行边缘提取参数:Image (input_object) : 单通道图像(数组)ImaAmp (output_object):多通道图像(数组),边缘振幅或梯度大小图像。ImaAmp输出变量,说的是edges的amplitude,其实就是梯度的大小(因为边缘_halcon轮廓提取

【PLS预测】基于PCA主成分分析结合PLS实现近红外光谱检测的菠萝含水率预测附matlab代码_近红外数据pca分析-程序员宅基地

文章浏览阅读967次,点赞26次,收藏24次。近红外光谱技术(NIRS)是一种快速、无损的分析技术,已广泛应用于水果品质检测中。本文提出了一种基于主成分分析(PCA)和偏最小二乘回归(PLS)相结合的近红外光谱预测菠萝含水率的方法。该方法利用PCA降维提取光谱特征,并通过PLS建立光谱与含水率之间的定量关系模型.数据预处理:对光谱数据进行标准正态变换和一阶导数处理利用PCA对光谱数据进行降维处理,提取主成分PLS模型建立:采用PLS算法建立光谱与含水率之间的定量关系模型交叉验证法优化PLS模型参数,包括成分数和正则化参数。_近红外数据pca分析

【电赛实战】混沌信号产生实验装置 2022年D题_电赛要求单电源供电-程序员宅基地

文章浏览阅读4.6k次,点赞10次,收藏67次。系统基于蔡氏电路,以运算放大器单元构成主拓扑结构,搭建蔡氏电路系统的功能全同电路,使用电阻、电容和运算放大器三种基本器件设计了一个能生成稳定周期信号和混沌信号的信号产生实验装置。装置采用单电源供电,通过拨码开关选择产生不同种类信号。经测试,系统完成了题目部分要求,能够产生单倍、二倍、三倍周期的稳定周期相图以及单涡旋混沌信号相图和双涡旋混沌信号相图,且幅度不小于电源电压 VCC 的 80%,基本满足题目对装置性能的要求。_电赛要求单电源供电

基于Java+Vue+uniapp微信小程序游戏账号交易系统设计和实现_微信游戏小程序购买-程序员宅基地

文章浏览阅读3.3k次,点赞20次,收藏26次。随着网络和计算机技术的发展,各行各业出现了新的生机。各种办公软件和网站充斥到日常生活中,并在实践中不断的进步和发展。目前办公软件和网站技术已非常成熟,可以为用户提供更好的工作帮助。游戏近几年成为热门商品,对于游戏账号的购买最常用的有联系其它用户进行私下交易和网上购买。自己去联系他人购买需要机会,而且由于彼此不信任而使大部分人们放弃。网上购买的使用量非常高,相对应的管理工作也增加。到目前为止,人们网上交易一般去淘宝、京东等平台。这类平台属于第三方平台需要大量的推广费用,造成卖家成本增加而使很多的卖家望而却步。_微信游戏小程序购买

mysql 根据查询条件自定义排序(FIELD)_mysql更具查询出的值作为条件 来判断 对应的排序-程序员宅基地

文章浏览阅读2.2w次。MySQL可以通过field()函数自定义排序遇到一个需求,需要根据前端入参的参数顺序,查询后顺序返回对应的数据;正常编写sql自定义排序函数field()加持sql(得到了想要的结果)MyBatis中这个样子<select id="selServiceItemsByIdList" parameterType="com.xxx.entity.TServiceItems" resultMap="BaseResultMap"> select <include re_mysql更具查询出的值作为条件 来判断 对应的排序

推荐文章

热门文章

相关标签