Đang chuẩn bị liên kết để tải về tài liệu:
C++ Lab 8 Functions
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
When we build a house why do we make rooms? In our daily life why do we use so many different people who specialize in different professions, such as physicians, lawyers, accountants, etc? Same reasoning can be applied to programming. When we write a good program, it must be divided into modules; each module is designed to do a particular task. In C++ there are two types of modules, functions and classes. In this chapter we will deal with functions. You can write functions that can be used over and over again in a program or in several programs. In. | Lab 8 F unctions When we build a house why do we make rooms In our daily life why do we use so many different people who specialize in different professions such as physicians lawyers accountants etc Same reasoning can be applied to programming. When we write a good program it must be divided into modules each module is designed to do a particular task. In C there are two types of modules functions and classes. In this chapter we will deal with functions. You can write functions that can be used over and over again in a program or in several programs. In fact the C standard library comes with many functions for mathematical string and character manipulations. A large programming job needs to be broken down to manageable smaller modules this breaking down process is called top down design. Here is a popular poem written using functions. I have broken down the poem into four functions four verses and one chorus. The main function simply calls the other functions. Even though the program is given in two text boxes for clarity please combine them into one program. Program 8-1 Program Function Calls Written by Dr. John P. Abraham Instructional objective Functions include iostream using namespace std void chorus void verse1 void verse2 void verse3 void verse4 int main verse1 chorus verse2 chorus verse3 chorus verse4 chorus return 0 Program 2-1 continued __ void chorus cout nTwinkle twinkle little star cout nHow I wonder what you are cout nUp above the world so high cout nLike a diamond in the sky n void verse1 cout nWhen the blazing sun is gone cout nWhen he nothing shines upon cout nThen you show your little light cout nTwinkle twinkle all the night. n void verse2 cout nThen the traveler in the dark cout nThanks you for your tiny spark cout nHe could not see which way to go cout nIf you did not twinkle so. n void verse3 cout nIn the dark blue sky you keep cout nAnd often through my curtains peep cout nFor you never shut your eye cout nTill the