c++编程题

作者&投稿:蓍牵 (若有异议请与网页底部的电邮联系)
C++编程题,用代码实现~



#include
using namespace std;
#define MA_MAX 100
int main(){
int n=1, matrix[MA_MAX][MA_MAX]={0};
cin >> n;
if(n 100)
exit(-1);
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
cin >> matrix[i][j];

for(int j = n-1; j >= 0; j--){
for(int i = n-1; i >= 0; i--){
cout << matrix[i][j];
if(i != 0)
cout << " ";
}
cout << std::endl;
}
return 1;
}

#include <iostream>
using namespace std;

//
// 二维座标类简单实现
//

class Vector2d
{
//构造/析构函数
public:
Vector2d()
{}

Vector2d(double _x, double _y)
:x(_x), y(_y)
{}

~Vector2d()
{}

//成员函数
public:
//输出函数
void Show()
{
cout << "x=" << x << ", y=" << y <<"." << endl;
}

//+重载运算符
Vector2d operator + (const Vector2d& v)
{
Vector2d vec;
vec.x = x + v.x;
vec.y = y + v.y;

return vec;
}

private:
double x;
double y;
};
//////////////////////////////////////////////////////////////////////////

//
// 立方体类简单实现
//
class CBox
{
//构造/析构函数
public:
CBox()
{
m_nSideLength=0;
}

~CBox()
{
}

//成员函数
public:
//设置边长
void SetSideLength(unsigned short nSideL)
{
m_nSideLength=nSideL;
}

//获得边长
unsigned short GetSideLength() const
{
return m_nSideLength;
}

//表面积
unsigned short S()
{
return m_nSideLength*m_nSideLength*6;
}

//体积
unsigned short V()
{
return m_nSideLength*m_nSideLength*m_nSideLength;
}

//成员变量
private:
unsigned short m_nSideLength;
};
//////////////////////////////////////////////////////////////////////////

//
// 员工抽象简单实现
//
#define MAX_NAME 64

class Employee
{
//构造/析构函数
public:
Employee()
{
name=0;
ID=0;

name = new char[MAX_NAME];
}

virtual ~Employee()
{
if (name) delete name;
}

public:
//设置员工信息
void SetEmployeeInfo(const char* _name, unsigned short _ID)
{
strncpy(name, _name, sizeof(char)*MAX_NAME);
ID=_ID;
}

//计算员工工资
virtual int GetSalary() = 0;

//员工信息
virtual void ShowEmployeeInfo()
{
if (name[0]!='\0') cout<< "姓名:" << name << ",员工编号:" << ID << ".";
else cout<< "该员工没有任何信息" <<endl;
}

//成员变量
protected:
char* name;
unsigned short ID;
};

//
// 经理类简单实现
//
class Manager : public Employee
{
//构造/析构函数
public:
Manager()
{
sal=0;
}

virtual ~Manager()
{}

//虚函数继承
public:
//员工信息
virtual void ShowEmployeeInfo()
{
cout<< "经理简介" <<endl;
__super::ShowEmployeeInfo();
}

//计算员工工资
virtual int GetSalary()
{
return sal;
}

//成员函数
public:
//设置薪水
void SetSalary(int salary)
{
sal = salary;
}

//内部成员变量
private:
int sal;
};

//
// 钟点工简单实现
//
class HourlyWorker : public Employee
{
//构造/析构函数
public:
HourlyWorker()
{
wage=0;
hours=0;
}

virtual ~HourlyWorker()
{}

//虚函数继承
public:
//员工信息
virtual void ShowEmployeeInfo()
{
cout<< "钟点工简介" <<endl;
__super::ShowEmployeeInfo();
}

//计算员工工资
virtual int GetSalary()
{
return wage*hours;
}

//成员函数
public:
//设置薪水
void SetSalary(int _wage, int _hours)
{
wage=_wage;
hours=_hours;
}

//内部成员变量
private:
int wage;
int hours;
};
//////////////////////////////////////////////////////////////////////////

//
// 函数模版绝对值的简单实现
//
template <class Type>
Type Abs(Type tVar)
{
if (tVar >= 0) return tVar;
else return -tVar;
}
//////////////////////////////////////////////////////////////////////////

//
// 复数类简单实现
//
class CComplex
{
//构造/析构函数
public:
CComplex()
{}

CComplex(int _a, int _b)
:a(_a), b(_b)
{}

~CComplex()
{}

//成员函数
public:
//设置复数实部虚部
void SetComplex(int _a, int _b)
{
a=_a;
b=_b;
}

//输出函数
void Show()
{
char* signal=b>0?"+":"";
cout << "该复数是:" << a << signal << b <<"i" << endl;
}

//+重载运算符
CComplex operator + (const CComplex& c)
{
CComplex complex;
complex.a = a + c.a;
complex.b = b + c.b;

return complex;
}

//成员变量
private:
int a;
int b;
};
//////////////////////////////////////////////////////////////////////////

//
// 简单形状类简单实现
//
class CShape
{
public:
//获取周长
virtual float GetLength()=0;
};

//
// 四边形类简单实现
//
class CSquare : public CShape
{
//构造/析构函数
public:
CSquare()
{
a=b=c=d=0;
}

~CSquare()
{}

//虚函数继承
public:
virtual float GetLength()
{
return (float)(a+b+c+d);
}

//设置边长
public:
void SetSide(int _a, int _b, int _c, int _d)
{
a=_a;
b=_b;
c=_c;
d=_d;
}

//成员变量
private:
int a, b, c, d;
};

//
// 圆类简单实现
//
#define PI 3.14159265
class CCircle : public CShape
{
//构造/析构函数
public:
CCircle()
{
r=0;
}

~CCircle()
{}

//虚函数继承
public:
virtual float GetLength()
{
return (float)(PI*r*2);
}

//设置半径
public:
void SetRadius(int _r)
{
r=_r;
}

//成员变量
private:
int r;
};
//////////////////////////////////////////////////////////////////////////
//
// 时间类简单实现
//
class CDateInfo
{
//构造/析构函数
public:
CDateInfo()
{
year=2010;
month=8;
day=8;
}

CDateInfo(unsigned short _year, unsigned short _month, unsigned short _day)
:year(_year), month(_month), day(_day)
{
}

~CDateInfo()
{}

public:
//设置日期
void SetDateInfo(unsigned short _year, unsigned short _month, unsigned short _day)
{
year=_year;
month=_month;
day=_day;
}

//日期显示
void ShowDateInfo()
{
cout<< "当前日期是:" << year << "年-" << month << "月-" << day << "日" << endl;
}

//成员变量
private:
unsigned short year,month, day;
};
//////////////////////////////////////////////////////////////////////////
int main()
{
cout<< "第2题:演示2d坐标类" <<endl;
Vector2d v1(1, 2), v2(2, 3);
v1.Show();
v2.Show();

Vector2d v = v1 + v2;
v.Show();
cout<< "-------------------------------" << endl << endl;

cout<< "第3题:演示立方体" << endl;
CBox b;
b.SetSideLength(5);
cout<< "边长是:" << b.GetSideLength() << ",面积=" << b.S() << ",体积=" << b.V() << "." <<endl;
cout<< "-------------------------------" << endl << endl;

cout<< "第4题:演示员工" << endl;
//经理
Manager m;
m.SetEmployeeInfo("张三", 10001);
m.SetSalary(8500);
m.ShowEmployeeInfo();
cout<< " 薪水:" << m.GetSalary() << "." <<endl;

//钟点工
HourlyWorker hw;
hw.SetEmployeeInfo("李四", 10002);
hw.ShowEmployeeInfo();
hw.SetSalary(13, 120);
cout<< " 薪水:" << hw.GetSalary() << "." <<endl;
cout<< "-------------------------------" << endl << endl;

cout<< "第5题:演示模版绝对值" << endl;
cout<< "浮点数" << Abs(-3.14159f) << endl;
cout<< "整数" << Abs(96) << endl;
cout<< "长整数" << Abs(3680L) << endl;
cout<< "-------------------------------" << endl << endl;

cout<< "第6题:演示复数" << endl;
CComplex c(-1, 9);
c.Show();
c.SetComplex(15, -36);
c.Show();
cout<< "-------------------------------" << endl << endl;

cout<< "第7题:填空题" << endl;
cout<< "1. 输出结果是: 1251121" << endl;
cout<< "2. 私有的" << endl;
cout<< "3. 虚基类" << endl;
cout<< "4. 模版函数如下:" << endl;
cout<< "template <class T>" << endl;
cout<< "T DBL(T v)"<<endl;
cout<< "{"<<endl;
cout<< " return v+v;"<<endl;
cout<< "}"<<endl;
cout<< "5. int GETNUM() { return x; }" << endl;
cout<< "-------------------------------" << endl << endl;

cout<< "第8题:演示图形周长" << endl;
CSquare s;
s.SetSide(1,2,3,4);
cout<< "四边形周长:" << s.GetLength() <<endl;
CCircle cir;
cir.SetRadius(1);
cout<< "圆形的周长:" << cir.GetLength() <<endl;
cout<< "-------------------------------" << endl << endl;

cout<< "第9题:演示日期" << endl;
CDateInfo date;
date.ShowDateInfo();
date.SetDateInfo(2012,12,12);
date.ShowDateInfo();
cout<< "-------------------------------" << endl << endl;

return 0;
}

/////////////////////////////////////////////////////////////
兄弟,第10题你自己做好么?参考第六题演示复数的类 自己写个吧。我的手都酸痛了……
我明白了,什么叫坚持到底,手都酸痛了……
兄弟,给哥点吃的吧?


c++编程题,求大神解答。
基本思想是计算相邻的机器人每轮发生碰撞的时间,从小到大排列后依次发生碰撞 剩下的机器人相邻关系会改变,重新计算碰撞时间,重复上述步骤,直到没有碰撞发生 C++代码如下:include <bits\/stdc++.h> \/\/ C++万能头文件 using namespace std;using tri = tuple<double, int, int>; \/\/ 发生碰撞的...

求一些c编程题
2009-07-24 求一简单C语言编程题 1 2011-06-27 各种求!!!c语言编程题!!!1 1 2018-12-06 高分求一c语言编程题(急!!!) 2008-08-10 求1些锻炼 c编程能力的题目 2009-10-19 求一个C语言编程题 2012-01-04 求c语言编程题 1 2009-12-13 求一适合C语言编程题,适合初学者,要有点难度滴 ...

c语言编程题
include<stdio.h>#include<string.h>#define N 200int del(char *str, int k, int m){ int i,l; char t; if(str==NULL) return 0; l=strlen(str); if(k<1||k>l||m<1) return 0; if(k+m>l) { str[k-1]='\\0'; return 1; } for(...

c语言编程题,麻烦写在纸上,谢谢了~~
第一题:for()循环 include<stdio.h> int main(){ int i=0,sum=0;for(i=1; i<=100; i++){ sum=sum+i;} printf("%d\\n",sum);return 0;} while()循环 include<stdio.h> int main(){ int i=0,sum=0;while(i<=100){ sum=sum+i;i++;} printf("%d\\n",sum);return 0...

想找一些C++编程例题
一:选择题 1. 下面函数的功能是:( )int fun(char *x){ char *y=x;while(*y++){};return y-x-1;} a. 求字符串的长度 b. 求字符串存放位置 c. 比较两个字符串的大小 d. 将字符串x连接到字符串y后面 2. 若有以下说明和语句,且0<i<10,则( )是对数组元素的错误引用。int...

Java 基础编程题求解,不是很懂
第一种:方式借助于,while循环获取,提示输入内容获取输入值,然后判断如果余数为5结束循环。int i = 0;do{System.out.println("请输入数据边界值:");\/\/获取输入数字Scanner sc = new Scanner(System.in);int s = sc.nextInt();i = s%10;if(i == 5){System.out.println(s);sc.close...

C语音编程题(一个班级有N个学生,每个学生有学号、姓名,学生学习课程...
C语言包含的各种控制语句仅有9种,关键字也只有32个,程序的编写要求不严格且以小写字母为主,对许多不必要的部分进行了精简。实际上,语句构成与硬件有关联的较少,且C语言本身不提供与硬件相关的输入输出、文件管理等功能,如需此类功能,需要通过配合编译系统所支持的各类库进行编程,故c语言拥有非常...

C语言问题编程问题?
include <stdio.h> int main(){ int i,j,n=-1;float scores[30],sum=0,temp;printf("请输入n的值(0~30):");while(n<0 || n>30) scanf("%d",&n);if(!n) return 0;for(i=0;i<n;scanf("%f",&scores[i]),sum+=scores[i],i++)printf("请输入学生%d分数:",i+1);p...

c语言编程题 求解
从键盘输入一个字符串,可以设计一个函数实现把字符串中奇数位置的字符取出来并转为大写的。输入kobe结果是KB指定子函数:voidGetSubStr(charst[])include <stdio.h> void GetSubStr(char st[]){int i,j;for(i=j=0;st[i];i++)if(i%2==0)st[j++]=(st[i]>='a'&&st[i]<='z'?st...

C语言编程题 求解
按照题意,表格使用结构链表实现。其中成员班级或工龄,使用自定义的联合体union(就是题目要求的共用体)。函数异常不做处理,直接抛出,你需要可以在调用时判断处理异常。include <stdio.h> include <malloc.h> typedef union info4 { char cName[10];\/\/班级名称 int wAge;\/\/工龄 }IO4;typedef ...

陵县13656949857: 求助:3道C++的编程题~!~!~!~!~!!!!! -
景昭冻干: //第一题#include void main() { int a,b,c; for(a=1;a for(b=0;b for(c=1;c if(100*(a+c)+10*(b+b)+a+c==1333) cout}//第二题#include #include int sushu(int n) { for(int i=2;i if(n%i==0) return 0; return 1; } void main() { int n; cout cin>>n; if(n%2!=0||n cout else ...

陵县13656949857: C++编程题目
景昭冻干: 以下程序通过测试. 附图. #include <iostream> using namespace std; int main() { int a,b,c,max,min,ave; cin>>a>>b>>c; max=a; //首先将最大值和最小值都初始化等于a. min=a; ave=(a+b+c)/3; //最大值和最小值分别跟b和c进行比较. if(max<b) ...

陵县13656949857: c++编程题 -
景昭冻干: #include void main() { int n,i,j=0,m=1; cout>n...

陵县13656949857: c++编程的四道题目 -
景昭冻干: 1:#include "stdio.h"void encrypt(char ch[],char chp[]){for(int i=0;ch[i]...

陵县13656949857: C++编程题. -
景昭冻干: #include inline void Swap(int &a,int &b) { int temp = a; a = b; b = temp; } int main(void) { int a[] = {3,5,12,6,56,8,1}; int len = sizeof(a)/sizeof(int); int max,min; max = min = a[0]; for (int i = 0; i{ if (a[i]>max) { max = a[i]; } if (a[i] { min = a[i]; } for (int j = 0; ...

陵县13656949857: C++编程题求助!急! -
景昭冻干: 都调试通过了 第一题:#include "iostream" using namespace std; template T getmin(T&x,T&y) { return x} int _tmain(int argc, _TCHAR* argv[]) { float x,y; cout cin>>x>>y; cout return 0; } 第二题:#include "iostream" using namespace std; ...

陵县13656949857: 一道C++编程题 -
景昭冻干: #include void inverse(char a[],char b[]){ int i,j,len=strlen(a); for(j=0,i=len-1;i>=0;--i,++j) b[j]=a[i]; b[len]='\0';}...

陵县13656949857: VC++编程题
景昭冻干: 第一题: #include<iostream.h> #include<math.h> int isprime(int n); void main() { cout<<"1-100的所有素数是:"<<endl; for(int i=2;i<=100;i++) { if(isprime(i)==1) cout<<i<<endl; } } int isprime(int n) { for(int i=2;i<=sqrt(n);i++) if(n%i==0) return 0; ...

陵县13656949857: C++编程题 C++编程题 C++编程题 -
景昭冻干: #include <iostream> using namespace std; const int inch2foot=12; const double inch2meter=0.0254; const double pound2kilo=2.2; int main() { double foot,inch,pound,BMI,height,weight; cout<<"输入身高(尺 cin>>foot>>inch; cout<<"输入体重(...

陵县13656949857: C++编程题目 -
景昭冻干: 你题目不清,但是根据提议随便写了点.//时间问题#include #include class c_mytime{public: c_mytime(); void showtime();protected: int year; int month; i...

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网