帮忙做下课程设计
1、 编写一个函数模板,判断两个任意类型的任意长度的数组是否相等。并写main函数验证。2、 写统计输入的正文中有多少单词的程序,这里的单词指的是用空白符分隔开的字符串。
3、 编写程序实现一个简单的加密器,实现英文字符串的加密。加密规则如下:将字符替换成它后面的第二个字符。比如'a'替换成'c','C'替换成'E','z'替换成'|'。"Panda"替换成"Rcpfc"。
4、 编程实现:从键盘输入一任意字符串,然后,输入所要查找字符。存在则返回它第一次在字符串中出现的位置;否则,输出"在字符串中查找不到!" 。并实现对同一字符串,能连续输入所要查找的字符。
5、 编程实现:从字符串中删除子字符串。从键盘输入一字符串,然后,输入要删除的子字符串。最后输出删除子串后的新字符串。
6、 编写几何图形圆的类Circle,包括两个属性:圆心O(用上题中的Point类实现)和半径R。成员函数包括:圆心位置获取函数GetO()和半径获取函数GetR();半径位置设置函数SetR();圆的位置移动函数MoveTo();圆的半径设置函数SetR();以及圆的信息打印函数Display()。
7、 编写复数类Complex。实现各种常用构造函数,实现整数、实数向复数的转化函数,实现整数、实数和复数以及复数之间的加、减、乘、除各种运算,实现==、!=等逻辑运算。
8、 编写几何点(二维平面上)的类Point,包括位置属性(二维坐标x,y),成员函数包括点的位置获取函数GetX()和GetY(),点的位置设置函数SetX()和SetY(),和点的位置移动函数MoveTo()以及点的信息打印函数Display()。
9、 利用静态数据成员的概念,编写一个类,可以统计目前存在多少个该类的对象。
10、 生成一个Object抽象类,在其中声明CalArea()、IsIn()纯虚函数,从Object派生出Rect类、Circle类,实现这些函数。
11、 下列shape类是一个表示形状的抽象类,area( )为求图形面积的函数,total( )则是一个通用的用以求不同形状的图形面积总和的函数。请从shape类派生三角形类(triangle)、矩形类(rectangle),并给出具体的求面积函数。
class shape{
public:
virtual float area( )=0;
};
float total(shape *s[ ],int n)
{
float sum=0.0;
for(int i=0;i<n;i++)
sum+=s[i]->area( );
return sum;
}
12、 定义一个字符栈类Stack(包括类的实现)。数据成员包括一个存放字符的数组stck[ ]和一个栈指针tos。栈数组的尺寸由常量SIZE确定。栈的基本操作为Push()和Pop()。
13、 完成下面的函数,对有n个元素的数组a,使数组元素按逆序排列。
void inverse(int *a, int n)
{
}
14、 下面的函数统计子字符串substr在字符串str中出现的次数,如果substr在str中不出现,则返回值0。请完成该函数。
int str_count(char *substr, char *str)
{
}
15、 编写一个String类,表示一个字符串,并重载其+运算符,表示字符串的连接。
16、 编写一个String类,表示一个字符串,并重载其=运算符,表示字符串的拷贝。
17、 编写一个String类,表示一个字符串,并重载其==运算符,判断字符串是否相等。
18、 编写一个String类,表示一个字符串,并重载其<运算符,判断字符串长短。
19、 编写一个String类,表示一个字符串,并重载其前置++运算符,表示字符串的长度加一,即在当前字符串的后面追加一个" "字符。
20、 编写一个String类,表示一个字符串,并重载其后置++运算符,表示字符串的长度加一,即在当前字符串的后面追加一个" "字符。
21、 编写一个String类,表示一个字符串,并重载其前置--运算符,表示字符串的长度减一,即把当前字符串的最后面一个字符去掉。
22、 编写一个String类,表示一个字符串,并重载其后置--运算符,表示字符串的长度加一,即把当前字符串的最后面一个字符去掉。
23、 将如下类型抽象并组织成一个继承层次:图像文件格式(如gif, uiff, jpeg, bmp)。
24、 将如下类型抽象并组织成一个继承层次:交通工具(如汽车,火车,飞车,马车)。
25、 将如下类型抽象并组织成一个继承层次:C++的数据类型(基本类型,结构类型,类类型,指针类型,引用类型)
26、 头上有眼睛,鼻子,耳朵。眼睛可以看,鼻子可以闻,耳朵可以听。用程序描述出上述关系。
27、 学生信息管理系统中,包含的核心角色有,学生,班级,院系,宿舍,学号。请用继承与合成的知识描述上述关系。
28、 学校教务管理系统中,包含的核心角色有,用户,学生,老师,课程,成绩。请描述上述关系。
29、 编写程序,计算汽车运行的时间,首先建立基类car,其中含有数据成员distance存储两点间的距离。假定距离以英里计算,速度为每小时80英里,使用虚函数travel_time()计算并显示通过这段距离的时间。在派生类kilometre中,假定距离以千米计算,速度为每小时120千米,使用函数travel_time()计算并显示通过这段距离的时间。
30、 建立类模板input,在调用构造函数时,完成以下工作:
(1) 提示用户输入
(2) 让用户输入数据;
(3) 如果数据不在预定范围内,重新提示输入。
input型的对象应当按以下形式定义:input ob(“promput message”, min_value, max_value)
其中,promput message是提示输入的信息。可接受的最小值和最大值分别由min_value与max_value指定。
我好交差 好放假回家。 只有3道
/******************************************************************************
* Compare two arraies *
* *
* *
*Author: Edward *
* *
*Purpose: Just for testing. *
* *
*Useage: Compare two arraies who have any types in them *
* *
*Restriction: ??? *
* *
******************************************************************************/
#include <iostream>
using namespace std;
/*Compare two arraies, if they equals each other, return true, else return false*/
template <class Type>
bool Equal(Type source1[], Type source2[], int s1Length, int s2Length);
/*Main function*/
int main(void)
{
int i1[10] = {1, 1, 1, 1}, i2[6] = {1, 1, 1, 1}; //Define two int arraies to compare
char c1[10] = "Hello", c2[10] = "Hello"; //Define two char arraies to compare
/*Compare the two int arraies*/
if (Equal(i1, i2, 10, 6))
{
cout<<"The i1 and i2 are same!"<<endl;
}
else
{
cout<<"The i1 and i2 are not same!"<<endl;
}
/*Compare the two char arraies*/
if (Equal(c1, c2, 10, 10))
{
cout<<"The c1 and c2 are same!"<<endl;
}
else
{
cout<<"The c1 and c2 are not same!"<<endl;
}
/*End the program normally*/
return 0;
}
/**
*Name: Equal
*Function: Compare two arraies
*Params: The two arraies you want to compare and their lengthes.
*Return: If they are the same, return true, else return false.
**/
template <class Type>
bool Equal(Type source1[], Type source2[], int s1Length, int s2Length)
{
/*If their lengthes are not same, certainly the two arraies are not same*/
if (s1Length != s2Length)
{
return false;
}
/*If their lengthes are same, compare the two arraies' data one by one*/
for (int i = 0; i < s1Length; i++)
{
/*Find the different data, return false*/
if (source1[i] != source2[i])
{
return false;
}/*end if*/
}/*end for*/
/*Cannot find the different data, return true*/
return true;
}
××××××××××××××××××××××××××××××××××××××××××××
/******************************************************************************
* Count the number of the words in the sentence *
* *
* *
*Author: Edward *
* *
*Purpose: Just for testing. *
* *
*Useage: Count the number of the words in the given sentence *
* *
*Restriction: Here words means those char separated by blank *
* *
******************************************************************************/
#include <iostream>
using namespace std;
/*Count the words number in the sentence*/
int CountWord(char *str);
/*Main fucntion*/
int main(void)
{
char str[100]; //Store the sentence you input
/*Give an information and get the sentence*/
cout<<"Please input a sentence: "<<endl;
cin.getline(str, 100);
/*Output the result*/
cout<<"The number of words in the sentence you input is : "<<CountWord(str)<<endl;
/*End the program normally*/
return 0;
}
/**
*Name: CountWord
*Function: Count the number of the words in a sentence
*Params: The sentence you want to get word's number from
*Return: The word's number
**/
int CountWord(char *str)
{
int sum = 0; //Store the number of the words
int i = 0; //Loop flag
bool isBlank = true; //A flag to see the current is a blank or not
char c; //Store the singal char from the sentence
/*count the number until the string ends*/
while ((c = str[i++]) != '\0')
{
if (c == ' ')
{
isBlank = true;
continue;
}
else if (isBlank)
{
sum++;
isBlank = false;
}
}
return sum;
}
××××××××××××××××××××××××××××××××××××
/******************************************************************************
* encrypt a string,replace each char with the char two after it *
* *
* *
*Author: Edward *
* *
*Purpose: Just for testing. *
* *
*Useage: Encrypt a string you input *
* *
*Restriction: ??? *
* *
******************************************************************************/
#include <iostream>
using namespace std;
/*Main function*/
int main(void)
{
const int M = 100; //The max length of the string you input
int i = 0; //Loop flag
char str[M]; //Store the string you input
char c; //Store each char in teh string
/*Get a string from the user*/
cout<<"Please input a string: "<<endl;
cin>>str;
/*Ouput the string which is not encrypted*/
cout<<"At the begining : "<<endl;
cout<<str<<endl;
/*Replace each char in the string*/
while ((c = str[i]) != '\0')
{
str[i] += 2;
i++;
}
/*Output the string after encrypted*/
cout<<"After encrypt : "<<endl;
cout<<str;
/*End the program normally*/
return 0;
}
x炀````
x炀```````你这样搞不行啊````哈哈``被我抓住了``` [tk27] [tk27]人都不见了,白写3道了给你。
页:
[1]
