[THINKING IN C++]CHAPTER 03:EXERCISE 01

本文介绍了一个C++编程实践案例,通过创建多个不同类型的函数并分别定义它们的行为来演示如何使用C++进行模块化编程。具体包括声明和定义了void、char、int、float等类型的函数,并展示了如何在一个主函数中调用这些函数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

1. Creat a header file( with an extension of '.h'). In this file,
declare a group of functions by varying the argument lists and return
values from among  the following: void, char, int, and float. Now create
a .cpp file that    includes your header file and creates definitions
for all of these functions.  Each definition should simply print out
the function name, arguments list,   and return type so you know it's
been called. Create a second .cpp file that   includes your header file
and defines int main(), containing calls to all of   your functions.
Compile and run your program.

//: C03:01
//: Solution-01.h
/*    建立一个头文件。在这个文件里,声明一组拥有不同类型参数和返回值的函数:

void,char,int,float。建立一个cpp文件,包含你的头文件,建立所有这些函数的定义。每一个

定义只需打印出函数名,参数表,和返回值类型,以此知道这个函数被调用了。建立第二个cpp文

件包含你的头文件,定义int main(),包含调用所有你的函数。

*/


void funcv(void);
char funcc(char);
int funci(int);
float funcf(float);

 

//: C03:01
//: Solution-01-1.cpp {O}
#include
<iostream>
#include
"Solution-01.h"
using namespace std;

void funcv(void)
{
    cout
<<"void funcv(void)"<<endl;
}

char funcc(char c)
{
    cout
<<"char funcc(char c)"<<endl;
    
return c;
}

int funci(int i)
{
    cout
<<"int funci(int i)"<<endl;
    
return i;
}

float funcf(float f)
{
    cout
<<"float funcf(float f)"<<endl;
    
return f;
}

 

//: C03:01
//: Solution-01-2.cpp {L}

#include
"Solution-01.h"

int main()
{
    funcv();
    funcc(
'c');
    funci(
1);
    funcf(
1);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值