您的位置:首页 > 编程语言 > C语言/C++

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

2008-05-17 23:15 856 查看
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);


}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: