加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

《数据结构》实验一:VC编程环境灵活应用

发布时间:2020-12-15 06:04:41 所属栏目:安全 来源:网络整理
导读:一..实验目的 复习巩固VC编程环境的使用,以及C++模板设计。 1.回顾并掌握VC单文件结构程序设计过程。 2.回顾并掌握VC多文件工程设计过程 3.掌握VC程序调试过程。 4.回顾C++模板和模板的程序设计。 三.实验内容 1. 设计一个单文件结构程序完成从键盘输入两

一..实验目的

复习巩固VC编程环境的使用,以及C++模板设计。

1.回顾并掌握VC单文件结构程序设计过程。

2.回顾并掌握VC多文件工程设计过程

3.掌握VC程序调试过程。

4.回顾C++模板和模板的程序设计。

三.实验内容

1. 设计一个单文件结构程序完成从键盘输入两个数,输出二者的“和”和“积”的结果。

#include<iostream>
using namespace std;
int sum(int x,int y)
{
int temp;
temp=x+y;
return temp;
}
int mul(int x,int y)
{
int temp;
temp=x*y;
return temp;
}

int main()
{
int a,b,c,d;
cout<<"请输入两个数:";
cin>>a>>b;
c=sum(a,b);
d=mul(a,b);
cout<<"两数之和为:"<<c<<endl;
cout<<"两数之积为:"<<d<<endl;
return 0;
}



2.使用函数的模板来实现上述功能。

#include <iostream>
using namespace std;

template<class T>
void add(T a,T b) {
cout << "两数之和是" << a + b << endl;
}

template<class w>
void mul(w a,w b) {
cout << "两数之积是" << a * b << endl;
}

int main() {
float a,b;
cin >> a >> b;
add(a,b);
mul(a,b);
return 0;
}

3.使用一个类来实现上述功能。要求:

#include<iostream> using namespace std; class Add { public: Add(float a,float b); cout<<"两数之和为:"<<a+b<<endl; } class Mul { public: Mul(float a,float b); cout<<"两数之积为:"<<a*b<<endl; } int main(){ float a,b; cin>>a>>b; Add(a,b); Mul(a,b); cout<<"两数之和为:"<<" "<<endl; cout<<"两数之积为:"<<" "<<endl; return 0; }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读