[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.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//: C03:01
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//: Solution-01.h
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
/**//* 建立一个头文件。在这个文件里,声明一组拥有不同类型参数和返回值的函数:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
void,char,int,float。建立一个cpp文件,包含你的头文件,建立所有这些函数的定义。每一个
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
定义只需打印出函数名,参数表,和返回值类型,以此知道这个函数被调用了。建立第二个cpp文
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
件包含你的头文件,定义int main(),包含调用所有你的函数。
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
void funcv(void);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
char funcc(char);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
int funci(int);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
float funcf(float);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//: C03:01
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//: Solution-01-1.cpp {O}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include<iostream>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include"Solution-01.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using namespace std;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
void funcv(void)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"void funcv(void)"<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
char funcc(char c)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"char funcc(char c)"<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return c;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
int funci(int i)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"int funci(int i)"<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return i;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
float funcf(float f)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"float funcf(float f)"<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return f;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//: C03:01
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//: Solution-01-2.cpp {L}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include"Solution-01.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
int main()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
funcv();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
funcc('c');
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
funci(1);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
funcf(1);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
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.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//: C03:01
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//: Solution-01.h
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
/**//* 建立一个头文件。在这个文件里,声明一组拥有不同类型参数和返回值的函数:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
void,char,int,float。建立一个cpp文件,包含你的头文件,建立所有这些函数的定义。每一个
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
定义只需打印出函数名,参数表,和返回值类型,以此知道这个函数被调用了。建立第二个cpp文
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
件包含你的头文件,定义int main(),包含调用所有你的函数。
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
void funcv(void);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
char funcc(char);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
int funci(int);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
float funcf(float);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//: C03:01
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//: Solution-01-1.cpp {O}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include<iostream>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include"Solution-01.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using namespace std;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
void funcv(void)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"void funcv(void)"<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
char funcc(char c)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"char funcc(char c)"<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return c;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
int funci(int i)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"int funci(int i)"<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return i;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
float funcf(float f)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<"float funcf(float f)"<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return f;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//: C03:01
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//: Solution-01-2.cpp {L}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include"Solution-01.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
int main()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
funcv();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
funcc('c');
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
funci(1);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
funcf(1);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
相关文章推荐
- [THINKING IN C++]CHAPTER 03:EXERCISE 03
- [THINKING IN C++]CHAPTER 03:EXERCISE 06
- [THINKING IN C++]CHAPTER 03:EXERCISE 07
- [THINKING IN C++]CHAPTER 04:EXERCISE 04
- [THINKING IN C++]CHAPTER 03:EX 25
- [THINKING IN C++]CHAPTER 03:EX 26
- Templates in depth(Chapter 3 of Thinking in C++ Vol 2)
- Iostreams part2(Chapter 2 of Thinking in C++ Vol 2)
- STL Containers & Iterators part2(Chapter 4 of Thinking in C++ Vol 2)
- The C in C++(Chapter 3 of Thinking in C++)
- Thinking in C++ chapter 2
- Iostreams part1(Chapter 2 of Thinking in C++ Vol 2)
- Thinking in c++ exercise 4-26 关于二维数组指针
- STL Containers & Iterators part1(Chapter 4 of Thinking in C++ Vol 2)
- Thinking in C++ chapter 1
- thinking in C++ 读书日志(四)
- 【ThinkingInC++】17、使用函数指针
- 【ThinkingInC++】28、public的作用
- Inheritance & Composition(Chapter 14 of Thinking in C++)
- 【ThinkingInC++】68、模板介绍