1.12
— Chapter 1 comprehensive quiz
Question
1
एक single-file program लिखें (इसे main.cpp नाम दे) जो user से दो अलग-अलग integers लेता हो, उन्हें जोड़ता हो
और फिर result output करता हो । Program 3
functions use कर रहा होना चाहिए:
- एक “readNumber” नाम का function जो user
से integer लेकर caller को return
करेगा ।
- एक “writeAnswer” नाम का function जो केवल एक parameter लेगा और caller को कुछ भी return नहीं करेगा ।
- एक main() function,
जो ऊपर के दोनों functions को call
(और use) करेगा ।
Hint: आपको numbers को जोड़ने के लिए
अलग से कोई function लिखने की ज़रूरत
नहीं है (सीधे-सीधे operator + का इस्तेमाल करें) ।
Hint: आपको readNumber() को दो बार call करना पड़ेगा ।
Hint: यदि आप precompiled headers के साथ visual studio का इस्तेमाल कर रहे हो, तो #include “stdafx.h” को ना भूले ।
Hint: आपको readNumber() को दो बार call करना पड़ेगा ।
Hint: यदि आप precompiled headers के साथ visual studio का इस्तेमाल कर रहे हो, तो #include “stdafx.h” को ना भूले ।
Question
2
Exercise
1 में लिखे गये program को modify कर,
readNumber और writeAnswer()
को एक बिलकुल अलग file
“io.cpp” में move करे । अब इन्हें access करने के लिए main.cpp में इनका forward declaration लिखे ताकि main() इन्हें समझ पाए ।
Hint: यदि आपको इसमें कोई कठिनाई हो रही है, तो एक बार फिर से check कर ले की io.cpp आपके project में अच्छी तरह से
जुड़ा हुआ है ताकि ये compile हो सके । अधिक जानकारी के लिए section 1.8 -- Multiple files के साथ programs देखें ।
Question
3
Exercise
#2 में लिखे गए program को modify करें । इसमें io.h नाम का एक header file जोड़े ताकि main.cpp, forward declarations के बजाय directly इस header file को include करे । ध्यान रहे की आपका header file, header guards के साथ लिखा गया हो ।

No comments:
Post a Comment