自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(29)
  • 收藏
  • 关注

原创 学校的人事部门保存了有关学生的部分数据(学号、姓名、年龄、住址),教务部门也保存了学生的另外一些数据(学号、姓名、年龄、成绩),两个部门分别编写了本部门的学生数据管理程序,其中都用了Student作为

学校的人事部门保存了有关学生的部分数据(学号、姓名、年龄、住址),教务部门也保存了学生的另外一些数据(学号、姓名、年龄、成绩),两个部门分别编写了本部门的学生数据管理程序,其中都用了Student作为类名。现在要求在全校的学生数据管理程序中调用这两个部门的学生数据,分别输出两种内容的学生数据。要求用C++编程,使用命名空间。方法一:两个头文件,一个源文件(1)头文件header1:#include<iostream>#include<string>using namespa

2020-06-30 05:27:19 1517

转载 在例13.14的基础上,修改程序,将存放在c数组中的数据读入并显示出来。

在例13.14的基础上,修改程序,将存放在c数组中的数据读入并显示出来。方法一:#include<iostream>#include<sstream>//这是最新的头文件 #include<cstring>using namespace std;struct student{ int num; char name[20]; double score;};int main(){ student stud[3]= { 1001,"Li",

2020-06-28 23:09:16 397

转载 编写程序实现以下功能: (1)按职工号由小到大的顺序将5个员工的数据(包括号码、姓名、年龄、工资)输出到磁盘文件中保存。 (2)从键盘输入两个员工的数据(职工号大于已有的职工号),增加到文件的末尾。

编写程序实现以下功能:(1)按职工号由小到大的顺序将5个员工的数据(包括号码、姓名、年龄、工资)输出到磁盘文件中保存。(2)从键盘输入两个员工的数据(职工号大于已有的职工号),增加到文件的末尾。(3)输出文件中全部职工的数据。(4)从键盘输入一个号码,在文件中查找有无此职工号,如有则显示此职工是第几个职工,以及此职工的全部数据。如没有,就输出“无此人”。可以反复多次查询,如果输入查找的职工号为0,就结束查询。#include<iostream>#include<fstream&

2020-06-28 23:04:45 8459 6

转载 建立两个磁盘文件f1.dat和f2.dat,编写程序实现以下工作: (1)从键盘输入20个整数,分别存放在两个磁盘文件中(每个文件中放10个整数); (2)从f1.dat读入10个数,然后存放到f2.

建立两个磁盘文件f1.dat和f2.dat,编写程序实现以下工作:(1)从键盘输入20个整数,分别存放在两个磁盘文件中(每个文件中放10个整数);(2)从f1.dat读入10个数,然后存放到f2.dat文件原有数据的后面。(3)从f2.dat中读入20个整数,将它们按从小到大的顺序存放到f2.dat中(不保留原来的数据)。#include<iostream>#include<fstream>using namespace std;void fun1(){ int

2020-06-28 23:00:30 6311

原创 编写程序,在显示屏上显示一个由字母B组成的三角形。

编写程序,在显示屏上显示一个由字母B组成的三角形。方法一:用控制符输出格式#include<iostream>#include<iomanip> using namespace std;int main(){ for(int n=1;n<8;n++) { cout<<setw(20-n)<<setfill(' ')<<" "<<setw(2*n-1)<<setfill('B')<<"

2020-06-28 22:55:23 2532

转载 从键盘输入一批数值,要求保留3位小数,在输出时上下行小数点对齐。

从键盘输入一批数值,要求保留3位小数,在输出时上下行小数点对齐。方法一:用控制符控制输出格式#include<iostream>#include<iomanip>using namespace std;int main(){ float a[5]; cout<<"input data:"; for(int i=0;i<5;i++) { cin>>a[i]; } cout<<setiosflags(ios::f

2020-06-28 22:46:54 3976

原创 例13.15 在一个字符数组c中存放了10个整数,以空格相间隔,要求将它们放到整型数组中,再按大小排序,然后再存放回字符数组c中。

例13.15 在一个字符数组c中存放了10个整数,以空格相间隔,要求将它们放到整型数组中,再按大小排序,然后再存放回字符数组c中。法一:#include<iostream>#include<sstream>#include<cstring>using namespace std;int main(){ char c[50]="12 34 65 -23 -32 33 61 99 321 32"; int a[10],i,j,t; cout<&

2020-06-26 14:41:32 412

原创 例13.14 将一组数据保存在字符数组中。

例13.14 将一组数据保存在字符数组中。法一:#include<iostream>#include<sstream>//这是最新的头文件 #include<cstring>using namespace std;struct student{ int num; char name[20]; float score;};int main(){ student stud[3]= { 1001,"Li",78, 1002,"Wang"

2020-06-26 14:38:12 742

转载 例13.13 有5个学生的数据,要求: (1)把它们存到磁盘文件中。 (2)将磁盘文件中的第1,3,5个学生数据读入程序,并显示出来。 (3)将第3个学生的数据修改后存回磁盘文件中的原有位置。 (4)

例13.13 有5个学生的数据,要求:(1)把它们存到磁盘文件中。(2)将磁盘文件中的第1,3,5个学生数据读入程序,并显示出来。(3)将第3个学生的数据修改后存回磁盘文件中的原有位置。(4)从磁盘文件读入修改后的5个学生的数据并显示出来。#include<iostream>#include<cstring>#include<fstream>using namespace std;struct student{ int num; char nam

2020-06-26 14:29:06 1229

转载 例13.12 将执行例13.11程序时存放在磁盘文件中的二进制形式的数据读入内存并在显示器上显示。

例13.12 将执行例13.11程序时存放在磁盘文件中的二进制形式的数据读入内存并在显示器上显示。法一:#include<iostream>#include<fstream>using namespace std; struct student{ char name[20];//string name只是浅拷贝,只有指针的值,没有指针指向的值;char name[20]指针的值和指针指向的值都有 int num; int age; char sex;};

2020-06-26 14:24:55 442

转载 例13.11 将一批数据以二进制形式存放在磁盘文件中。

例13.11 将一批数据以二进制形式存放在磁盘文件中。法一:#include<iostream>#include<fstream>using namespace std; struct student{ char name[20]; int num; int age; char sex;};int main(){ student stud[3]= { "Li",1001,18,'f', "Fang",1002,19,'m', "Wang"

2020-06-26 14:18:28 593

转载 例13.10 从键盘读入一行字符,把其中的字母字符依次存放在磁盘文件f2.dat中。

例13.10 从键盘读入一行字符,把其中的字母字符依次存放在磁盘文件f2.dat中。#include<iostream>#include<fstream>using namespace std;void save_to_file(){ ofstream outfile("f2.dat"); if(!outfile) { cerr<<"open f2.dat error!"<<endl; exit(1); } char c[80];

2020-06-26 14:13:06 719

转载 例13.9 从例13.8建立的数据文件f1.dat中读入10个整数放在数组中,找出并输出10个数中的最大者和它在数组中的序号。

例13.9 从例13.8建立的数据文件f1.dat中读入10个整数放在数组中,找出并输出10个数中的最大者和它在数组中的序号。#include<iostream>#include<fstream>using namespace std;int main(){ int a[10],max,i,order; ifstream infile("f1.dat",ios::in);//ios::nocreate是在C++标准制定之前在<fstream.h>中有定义的

2020-06-26 14:03:36 1263 1

转载 例13.8 有一个整型数组,含10个元素,从磁盘输入10个整数给数组,将此数组送到磁盘文件中存放。

例13.8 有一个整型数组,含10个元素,从磁盘输入10个整数给数组,将此数组送到磁盘文件中存放。#include<iostream>#include<fstream>using namespace std;int main(){ int a[10]; ofstream outfile("f1.dat",ios::out);//或ofstream outfile("f1.dat"); if(!outfile) { cerr<<"open error

2020-06-26 14:01:41 1132

原创 编写任何显示构造函数重载和函数重载的程序。

Write any program which shows constructor overloading and function overloading.编写任何显示构造函数重载和函数重载的程序。#include<iostream>using namespace std;int add(int,int);//声明函数add,用于对两个整数的相加 double add(double,double);//声明函数重载add,用于对两个浮点数的相加 class Box{ p

2020-06-21 23:12:09 203

原创 编写任何显示函数重写的程序。

Write any program which shows function overriding.编写任何显示函数重写的程序。#include<iostream>using namespace std; class Shape{ public: virtual float area() const { return 0.0; } virtual float volume() const { return 0.0; } virtu

2020-06-21 23:10:38 159

原创 编写一个程序,用户使用for循环输入5个数字,所有这些数字将存储在一个数组中。之后,程序将添加这五个数字并显示结果。程序必须支持运算符重载的概念。

Write a program in which users enter 5 numbers using for loop and all these numbers will store in an array. After that program will add these five numbers and show the result. Your program must support the concept of operator overloading.编写一个程序,用户使用for循环输

2020-06-21 23:09:08 4243

原创 什么是多级继承?使用多级继承编写一个程序,用户在其中输入数字,计算数字的立方体,如果数字的立方体大于150,则打印结果立方体的平方,否则显示消息“对不起”。

What is Multilevel inheritance? Write a program using multi-level inheritance in which the user enters the number, calculate the cube of the number, if the cube of the number is greater than 150 then print the square of the resultant cube, otherwise show t

2020-06-21 23:06:31 328

原创 什么是单一和多重继承。编写程序,根据以下规则查找使用多重继承的学生的成绩; 成绩大于80分为甲级 成绩大于70分小于80分为B级 如果分数大于50且小于70,则为C级 如果分数小于40,则为F

What are single and multiple inheritances. Write a program to find the grades of a student using multiple inheritances according to the following rules;Grade A if marks are > 80Grade B if marks are >70 and < 80Grade C if marks are > 50 and &

2020-06-21 23:04:10 284

原创 编写一个使用多级继承的程序,其中用户输入一个数字,程序将显示从1到10的给定数字的表。

Write a program using multi-level inheritance in which user enter a number, the program will show the table of the given number from 1 to 10.编写一个使用多级继承的程序,其中用户输入一个数字,程序将显示从1到10的给定数字的表。#include <iostream>using namespace std;class Table { pub

2020-06-21 22:56:07 286

原创 什么是多态性?使用多态性编写一个程序,如果数字是正的,数字也是偶数,则用户输入数字,然后打印数字的立方,如果数字是奇数和负数,则打印数字的平方。

What is polymorphism? Write a program using polymorphism in which user enters the number if the number is positive and the number is also even, then print the cube of the number and if the number is odd and negative then print the square of the number.什么是

2020-06-21 22:53:54 187

转载 编写一个程序,定义抽象基类Shape,由它派生出5个派生类:Circle(圆形)、Square(正方形)、Rectangle(矩形)、Trapezoid(梯形)、Triangle(三角形)。用虚函数分

编写一个程序,定义抽象基类Shape,由它派生出5个派生类:Circle(圆形)、Square(正方形)、Rectangle(矩形)、Trapezoid(梯形)、Triangle(三角形)。用虚函数分别计算几种图形面积,并求它们的和。要求用基类指针数组,使它每一个元素指向一个派生类对象。#include<iostream>using namespace std;class Shape{ public: virtual double area() const=0;};clas

2020-06-19 22:44:02 21602

转载 编写一个程序,声明抽象基类Shape,由它派生出3个派生类:Circle(圆形)、Rectangle(矩形)、Triangle(三角形),用一个函数printArea分别输出以上三者的面积,3个图形的

编写一个程序,声明抽象基类Shape,由它派生出3个派生类:Circle(圆形)、Rectangle(矩形)、Triangle(三角形),用一个函数printArea分别输出以上三者的面积,3个图形的数据在定义对象时给定。#include<iostream>using namespace std;class Shape{ public: virtual double area() const=0;};class Circle:public Shape{ public

2020-06-19 22:42:39 12570 1

原创 假如增加一个Globe(圆球)类,写出完整的程序。

假如增加一个Globe(圆球)类,写出完整的程序。#include<iostream>using namespace std; class Shape{ public: virtual float area() const { return 0.0; } virtual float volume() const { return 0.0; } virtual void shapeName() const=0; };c

2020-06-19 22:41:12 299

原创 假如把Circle类更换成Globe(圆球)类,要求得到圆球的面积和体积,写出完整的程序。

假如把Circle类更换成Globe(圆球)类,要求得到圆球的面积和体积,写出完整的程序。#include<iostream>using namespace std; class Shape{ public: virtual float area() const { return 0.0; } virtual float volume() const { return 0.0; } virtual void shapeName()

2020-06-19 22:40:21 329

转载 虚函数和抽象基类的应用。在上一题中介绍了以Point为基类的“点-圆-圆柱体”类的层次结构。现在要对它进行改写,在程序中使用虚函数和抽象基类。类的层次结构的顶层是抽象基类Shape(形状)。Point

虚函数和抽象基类的应用。在上一题中介绍了以Point为基类的“点-圆-圆柱体”类的层次结构。现在要对它进行改写,在程序中使用虚函数和抽象基类。类的层次结构的顶层是抽象基类Shape(形状)。Point(点),Circle(圆,Cylinder(圆柱体)都是Shape类的直接派生类和间接派生类。#include<iostream>using namespace std; class Shape{ public: virtual float area() const { r

2020-06-19 22:39:22 573

转载 先建立一个Point(点)类,包含数据成员x,y(坐标点)。以它为基类,派生出一个Circle(圆)类,增加数据成员r(半径),再以Circle类为直接基类,派生出一个Cylinder(圆柱体)类,再

先建立一个Point(点)类,包含数据成员x,y(坐标点)。以它为基类,派生出一个Circle(圆)类,增加数据成员r(半径),再以Circle类为直接基类,派生出一个Cylinder(圆柱体)类,再增加数据成员h(高)。要求编写程序,重载运算符“<<”和“>>”,使之能用于输出以上类对象。#include<iostream>using namespace std; class Point{ public: Point(float x=0,float y=

2020-06-19 22:34:41 13707

转载 将第11.8节中的程序段加以补充完善,使之成为一个完整的程序。在程序中使用继承和组合。在定义Professor类对象prof1时给出所有数据的初值,然后修改prof1的生日数据,最后输出prof1的全

将第11.8节中的程序段加以补充完善,使之成为一个完整的程序。在程序中使用继承和组合。在定义Professor类对象prof1时给出所有数据的初值,然后修改prof1的生日数据,最后输出prof1的全部最新数据。#include<iostream>#include<cstring>using namespace std;class Teacher{ public: Teacher(int,const char[],char); void display();

2020-06-19 22:30:27 1141

转载 分别声明Teacher(教师)类和Cadre(干部)类,采用多重继承方式由这两个类派生出新类Teacher_Cadre(教师兼干部)类。要求: (1)在两个基类中都包含姓名、年龄、性别、地址、电话等数

分别声明Teacher(教师)类和Cadre(干部)类,采用多重继承方式由这两个类派生出新类Teacher_Cadre(教师兼干部)类。要求:(1)在两个基类中都包含姓名、年龄、性别、地址、电话等数据成员。(2)在Teacher类中还包含数据成员title(职称),在Cadre类中还包含数据成员post(职务)。在Tearcher_Cadre类中还包含数据成员wages(工资)。(3)对两个基类中的姓名、年龄、性别、地址、电话等数据成员用相同的名字,在引用这些数据成员时,指定作用域。(4)在类体中声

2020-06-19 22:28:42 5884

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除