Chapter 16 नरेंद्र शर्मा | class 11th | Ncert solution for Hindi Antra

NCERT Solutions for Class 11th: पाठ 16 – नरेंद्र शर्मा

प्रश्न अभ्यास

1. कविता के आधार पर बताइए कि कवि की दृष्टि में बाहर का अँधेरा भीतरी दुःस्वप्नों से अधिक भयावह क्यों है?

उत्तर

कवि ने भीतर के दुःस्वप्नों से भयावह समाज में व्याप्त कुव्यवस्था एवं कुरीतियों के अंधकार को माना है क्योंकि अंतर्मन का दुख तो उनका निजी दुख है, उनसे केवल एक व्यक्ति दुखी होता है, परंतु समाज की पीड़ाएँ समाज में चेतना का विकास नहीं होने देतीं| कवि का मन बेचैन है कि सुख और समृद्धि की सुबह कब होगी।

2. अंदर का भय कवि के नयनों को सुनहली भोर का अनुभव क्यों नहीं होने दे रहा है?

उत्तर

अंदर का भय कवि के नयनों को सुनहली भोर का अनुभव इसलिए नहीं होने दे रहा है क्योंकि उसे लगता है कि जैसे ही सुनहली भोर की शुरुआत होगी, उसके अंदर का भय उसे फिर से सताने लगेगा और वह चैन से नहीं रह पाएगा।

3. कवि को किस प्रकार की आस रातभर भटकाती है और क्यों?

उत्तर

कवि को यह आस रातभर भटकाती है कि एक-न-एक दिन उसके जीवन में आशा की किरण अवश्य फूटेगी। वह चाहता है कि जल्दी प्रकाश फैल जाए।

4. कवि चेतन से फिर जड़ होने की बात क्यों कहता है?

उत्तर

कवि चेतन से जड़ होने की बात इसलिए कहता है क्योंकि चेतन मनुष्य पर सांसारिक वातावरण अपना प्रभाव डालता है। उसे बाहर का अँधकार भयभीत करता है। इनसे बचने के लिए कवी जड़ होना चाहता है| कुछ समय के लिए उसे भय दूर रहेगा| इस तरह उसे सुबह का इंतज़ार करने की आवश्यकता नहीं पड़ेगी।

5. अंधकार भरी धरती पर ज्योति चकफेरी क्यों देती है? स्पष्ट कीजिए।

उत्तर

कवि संसार में व्याप्त विसंगतियों रूपी अंधकार को दूर करना चाहते हैं। वह कहते हैं जब तक इस धरती पर अंधकार है तब तक ज्योति अंधकार को दूर करने के लिए चारों ओर घूमती रहेगी यानी कवि धरती के अंधकार को दूर करने में लगे हुए हैं और जब तक यह अंधकार दूर नहीं होगा, वह इस कार्य में लगे रहेंगें|

6. निम्नलिखित पंक्तियों का भाव स्पष्ट कीजिए-

(क) आती नहीं उषा, बस केवल
आने की आहट आती है!

उत्तर

कवि को अपने जीवन और समाज में केवल अंधकार दिखाई दे रहा है। वह अपने जीवन में कुछ अच्छा होने की आशा कर रहे हैं। परन्तु ऐसा होता नहीं है इसलिए कवि का मन जीवन की निराशा में जूझता रहता है।

(ख) करवट नहीं बदलता है तम,
मन उतावलेपन में अक्षम!

उत्तर

इन पंक्तियों में कवि का आशय है कि जब जीवन में दुख रूपी अंधकार का साम्राज्य छा जाता है तो फिर लगने लगता है कि यह खत्म होगा| वह इस स्थिति से निपटने में खुद को असमर्थ पाते हैं इस कारण वह कुछ भी सोचने-समझने में अक्षम हैं।

7. जागृति नहीं अनिद्रा मेरी,
नहीं गई भव-निशा अँधेरी!
उक्त पंक्तियों में ‘जागृति’, ‘अनिद्रा’ और ‘भव-निशा अँधेरी’ से कवि का सामाजिक संदर्भों में क्या अभिप्राय है?

उत्तर

सामाजिक संदर्भों में ‘जागृति’ से अभिप्राय क्रान्ति का है| ‘भव-निशा अँधेरी’ का अर्थ समाज में व्याप्त रूढ़ियों से है जो लोगों के दुःखों का कारण बन गयी हैं| ‘अनिद्रा’ से आशय है सोने का| लोग समाज में व्याप्त इस अन्धकार को मिटाने का प्रयास नहीं कर रहे हैं जो नाश का कारण बानी हुई है|

8. ‘अंतर्नयनों के आगे से शिला न तम की हट पाती है’ पंक्ति में ‘अंतर्नयन’ और ‘तम की शिला’ से कवि का क्या तात्पर्य है?

उत्तर

‘अंतर्नयनों के आगे से शिला न तम की हट पाती है’ पंक्ति में अंतर्नयनों से कवि का तात्पर्य  ज्ञान चक्षुओं से तथा अंधकार की शिला से तात्पर्य अज्ञानता के पर्दे से है। जब तक मन में ज्ञान का प्रकाश नहीं फैलेगा, तब तक जीवन में चेतना नहीं आएगी।

Read More

Chapter 15 महादेवी वर्मा | class 11th | Ncert solution for Hindi Antra

NCERT Solutions for Class 11th: पाठ 15 – महादेवी वर्मा

प्रश्न-अभ्यास

जाग तुझको दूर जाना

1. ‘जाग तुझको दूर जाना’ कविता में कवयित्री मानव को किन विपरीत स्थितियों में आगे बढ़ने के लिए उत्साहित कर रही है?

उत्तर

इस कविता में कवयित्री मानव को आँधी, तूफ़ान, भूकंप की चिंता न करते हुए सांसारिक माया-मोह के बंधनों को त्यागकर, समस्त सुखों, भोग-विलासों को छोड़कर, समस्त कष्टों को भूलकर और कठिनाइयों का सामना करते हुए निरंतर अपने लक्ष्य को प्राप्त करने के लिए आगे बढ़ते रहने की प्रेरणा दे रही हैं।

2 कवयित्री किस मोहपूर्ण बंधन से मुक्त होकर मानव को जागृति का संदेश दे रही है?

उत्तर

कवयित्री मानव का सांसारिक मायामोह, सुख-सुविधाओं, भोग-विलास, नाते-रिश्ते आदि के बंधनों से मुक्त होकर निरंतर अपने लक्ष्य की ओर बढ़ते रहने के लिए मानव को जागृति का संदेश दे रही है।

3. ‘जाग तुझको दूर जाना’ स्वाधीनता आंदोलन की प्रेरणा से रचित एक जागरण गीत है। इस कथन के आधार पर कविता की मूल संवेदना को लिखिए।

उत्तर

महादेवी वर्मा द्वारा रचित कविता ‘जाग तुझको दूर जाना’ में स्वतंत्रता आंदोलन की परिस्थितियों का वर्णन किया गया है। इस कविता में कवयित्री ने देश के लोगों से कहा कि वह कठिन परिस्थितियों में भी आगे बढ़कर स्वतंत्रता आंदोलन में भाग लें| इसके लिए उन्हें सांसारिक मोह-माया को त्यागना होगा इस लिए वे इसकी चिंता ना करें| वे मंज़िल की ओर चलते रहें यानी स्वतंत्रता प्राप्ति के लिए कदम उठाते रहे|

4. निम्नलिखित पंक्तियों का काव्य-सौंदर्य स्पष्ट कीजिए-


(क) विश्व का क्रंदन” …………………………अपने लिए कारा बनाना!

उत्तर

कवयित्री भारतीयों को स्वतंत्रता प्राप्ति के लिए जागृति करते हुए कहती है कि जब देश पराधीनता की पीड़ा को झेल रहा है तो ऐसे में व्यक्तिगत सुखों को भोगने की इच्छा नहीं करनी चाहिए क्योंकि व्यक्तिगत सुख तभी अच्छे लगते हैं जब हमारे आसपास कोई दुखी न हो। यहाँ देश प्रेम की भावना प्रकट होती है। संस्कृतनिष्ठ खड़ी बोली का प्रयोग है। अनुप्रास, पुनरुक्तिप्रकाश तथा स्वरमैत्री अलंकार विद्यमान हैं।वीर रस और ओज गुण विद्यमान हैं।

(ख) कह न ठंडी साँस …………………………सजेगा आज पानी।

उत्तर

कवयित्री भारतीयों को स्वतंत्रता प्राप्ति के लिए जागृति करते हुए कहती है कि स्वतंत्रता के मार्ग में आने वाली निराशा भरी कहानी को भूल जाना चाहिए| योद्धा की आँखों में आँसू तभी अच्छे लगते हैं जब पराजय के बाद भी मन में युद्ध करने का जोश हो। हारे हुए योद्धा के आँसू आँखों की शोभा नहीं बढ़ाते। संस्कृतनिष्ठ खड़ी बोली का प्रयोग है। दूसरी पंक्ति में विरोधाभास अलंकार है। करुण रस एवं प्रसाद गुण विद्यमान हैं।

(ग) है तुझे अंगार-शय्या ………………………… कलियाँ बिछाना!

उत्तर

कवयित्री ने कठिन-से-कठिन परिस्थितियों में भी आगे बढ़ते रहने तथा परेशानियों, कष्टों से न घबराने की प्रेरणा दी गई है। संस्कृतनिष्ठ खड़ी बोली का प्रयोग है। ‘अंगार शैय्या’ में प्रतीकात्मक प्रयोग है।

5. कवयित्री ने स्वाधीनता के मार्ग में आनेवाली कठिनाइयों को इंगित कर मुनष्य के भीतर किन गुणों का विस्तार करना चाहा है? कविता के आधार पर स्पष्ट कीजिए।

उत्तर

इस कविता में कवयित्री ने साहस, धैर्य जैसे गुणों का विस्तार करना चाहा है| उन्होंने कहा कि कठिन परिस्थतियों में भी मनुष्य को अपना साहस नहीं छोड़ना चाहिए और मजबूती से उसका सामना करना चाहिए| साथ ही मनुष्यों को सांसारिक सुखों का त्याग कर मंज़िल की ओर अग्रसर रहना चाहिए| कवयित्री ने मनुष्य के भीतर के आलस्य त्यागकर और मन को शांत और स्थिर रखकर अपने उद्देश्य की पूर्ति में लग जाने को कहा है|

सब आँखों के आँसू उजले

6. महादेवी वर्मा ने ‘आँसू’ के लिए ‘उजले’ विशेषण का प्रयोग किस संदर्भ में किया है और क्यों?

उत्तर

कवयित्री ने ‘आँसू’ के लिए ‘उजले’ विशेषण का प्रयोग स्वप्न अर्थात् आशा और सत्य के संदर्भ में किया है क्योंकि सभी आँखों के सपने उजले होते हैं और सभी में सत्य पलता है अर्थात् आशापूर्ण भविष्य के सपनों में ही सत्य पलता है, जो हमेशा उज्ज्वल होता है।

7. सपनों को सत्य रूप में ढालने के लिए कवयित्री ने किन यथार्थपूर्ण स्थितियों का सामना करने को कहा है?

उत्तर

कवयित्री का मानना है कि सपनों को सत्य रूप में ढालने के लिए मनुष्य को जीवन में आनेवाली कठिनाइयों, सुख-दुखों आदि का साहसपूर्वक सामना करना चाहिए और किसी भी स्थिति में घबराना नहीं चाहिए।

8. निम्नलिखित पंक्तियों का भाव स्पष्ट कीजिए-

(क) आलोक लुटाता वह ………………………… कब फूल जला?

उत्तर

कवयित्री का मानना है कि परमात्मा ही इस संसार के प्राणियों को सुख दुख देता है। कभी वह संसार को सूर्य के प्रकाश से तो कभी फूलों को सुगंध से भर देता है। दोनों ही संसार में आनंद बिखेरते हैं परंतु ये सब कब और कैसे होगा यह उस परमात्मा पर ही निर्भर करता है।

(ख) नभ तारक-सा……………..हीरक पिघला?

उत्तर

कवयित्री कहती है कि सूर्य के अस्त होते ही वातावरण अंधकारमय हो जाता है फलस्वरूप दिन का सूर्य रूपी सत्य रात को चाँद-सितारे बनकर आकाश को चूमता प्रतीत होता है। यानी हर मनुष्य अपने हिसाब से जी रहे हैं| हीरा तराशे जाने की अनेक कठिनाइयाँ सहने से भी नहीं डरता। सोना आग में तपकर और अधिक चमकीला बन जाता है। फिर भी सोने ने न तो कभी हीरे की तरह अनमोल बनने के लिए टूटना या छुरे से तराशा जाना स्वीकार किया और न कभी हीरे ने सोने की-सी चमक प्राप्त करने के लिए आग में तपना स्वीकार किया।

9. काव्य-सौंदर्य स्पष्ट कीजिए। संसृति के प्रति पग में मेरी एकाकी प्राण चला!

उत्तर

इन पंक्तियों में कवयित्री कहती हैं कि इस दुखी संसार में सुख-दुख एकाकार होकर मेरे प्राण अकेले चले जा रहे हैं अर्थात मेरे जीवन का अंत होनेवाला है और मैंने यह जान लिया है कि जीवन के प्रत्येक स्वप्न में सत्य समाहित होता है। ‘प्रति पग’ तथा ‘जलते खिलते बढ़ते’ में अन्त्यानुप्रास अलंकार है। भाषा तत्सम प्रधान, लाक्षणिक एवं प्रतीकात्मक है। उद्बोधनात्मक शैली है। गेयता का गुण विद्यमान है।

Read More

Chapter 14 सुमित्रानंदन पंत | class 11th | Ncert solution for Hindi Antra

NCERT Solutions for Class 11th: पाठ 14 -सुमित्रानंदन पंत

प्रश्न-अभ्यास

1. संध्या के समय प्रकृति में क्या-क्या परिवर्तन होते हैं, कविता के आधार पर लिखिए।

उत्तर

संध्या के समय सूर्य का प्रकाश लाल आभा लिए हो जाता है और झरनों से बहनेवाले जल का वर्ण स्वर्णिम हो जाता है। ये किरणें गंगाजल को स्वर्णिम करती हुई उसके किनारे की रेत पर धूपछाँही बना देती है। जैसे-जैसे सूर्य डूबता जाता है वैसे-वैसे प्राकृतिक परिवेश बदलता रहता है। तांबाई से स्वर्णिम, फिर सुरमई और सूर्य के डूबते ही अँधेरा छा जाता है।

2. पंत जी ने नदी के तट का जो वर्णन किया है, उसे अपने शब्दों में लिखिए।

उत्तर

नदी के तट पर ध्यान में मगन वृद्ध औरतें ऐसे प्रतीत हो रही हैं, मानो शिकार करने के लिए नदी किनारे खड़े बगुलें हों। पंत जी ने कविता में वृद्ध औरतों की बहुत सुंदर उपमा दी है। उनके दुख को भी बहुत सुंदर ढंग से प्रस्तुत किया है। नदी की मंथर धारा को वृद्ध औरतों के मन में बहने वाले दुख के समान बताया गया है। इस तरह से वृद्ध औरतें और बगुले दोनों ही नदी किनारे में मिलते हैं। उनके सफेद रंग के कारण कवि ने बहुत सुंदर उपमा देकर दोनों को एक कर दिया है।

3. बस्ती के छोटे से गाँव के अवसाद को किन-किन उपकरणों द्वारा अभिव्यक्त किया गया है?

उत्तर

शाम होते ही कृषक, उनकी गाएँ तथा पक्षी घर की और लौट पड़ते हैं।

4. लाला के मन में उठनेवाली दुविधा को अपने शब्दों में लिखिए।

उत्तर

लाला अपनी छोटी एवं संकुचित दुकान को देखकर वह स्वयं को दयनीय, दुखी और अपमानित अनुभव करता है। जीवन-भर अपनी दुकान की गद्दी पर बैठा हुआ उसे ऐसा लगता है जैसे किसी निर्जीव और बेकार अनाज का ढेर हो। वह सोचता था कि शहर में रहने वाले बनियों के समान वह उठ क्यों नहीं पाता? वह थोड़ी-सी आय के लिए बात-बात में झूठ बोलता है तथा अपने ही वर्ग के साथ प्रतिस्पर्धा के कारण अपने जीवन को तबाह कर रहा है।

5. सामाजिक समानता की छवि की कल्पना किस तरह अभिव्यक्त हुई है?

उत्तर

सामाजिक समानता की छवि की कल्पना इस प्रकार अभिव्यक्त हुई है-
• कर्म तथा गुण के समान ही सकल आय-व्यय का वितरण होना चाहिए।
• सामूहिक जीवन का निर्माण किया जाए।
• सब मिलकर नए संसार का निर्माण करें।
• सब मिलकर सभी प्रकार की सुख-सुविधाओं का भोग करें।
• समाज को धन का उत्तराधिकारी बनाया जाए।
• सभी व्याप्त वस्त्र, भोजन तथा आवास के अधिकारी हों।
• श्रम सबमें समान रूप से बँटें।

6. ‘कर्म और गुण के समान..”हो वितरण’ पंक्ति के माध्यम से कवि कैसे समाज की ओर संकेत कर रहा है?

उत्तर

इस पंक्ति में कवि ऐसे समाज की कल्पना कर रहा है, जहाँ का वितरण मनुष्य के कर्म और गुणों के आधार पर होना चाहिए। ऐसे में प्रत्येक मनुष्य को उसके गुणों और कार्य करने की क्षमता के आधार पर कार्य मिलेगा, इससे आय का सही प्रकार से बँटवारा हो सकेगा। ये समाजवाद के गुण हैं, जिसमें किसी एक वर्ग का आय-व्यय पर अधिकार नहीं होता है। सबको समान अधिकार प्राप्त होते हैं।

7. निम्नलिखित पंक्तियों का काव्य-सौंदर्य स्पष्ट कीजिए-
(क) तट पर बगुलों-सी वृद्धाएँ
विधवाएँ जप ध्यान में मगन, मंथर धारा में बहता
जिनका अदृश्य, गति अंतर-रोदन!

उत्तर

प्रस्तुत पंक्तियां कविवर सुमित्रानंदन की कविता ‘संध्या के बाद’ से ली गयी हैं जिसमें कवि ने बहुत ही सुंदर और मार्मिक रूप में प्रकृति का चित्रण किया है। कवि ने सांध्यकालीन वातावरण में नदी के तट पर बैठी बूढ़ी स्त्रियों और विधवाओं की दशा का वर्णन किया है जो ऐसे ध्यान मग्न होकर परमात्मा का नाम जप रही हैं जैसे बगुले ध्यानपूर्वक पानी देख रहे हों| उनके हृदय में दुख की मंथन धारा बह रही है। इस काव्यांश की प्रत्येक पंक्ति में काव्य सौंदर्य अद्भुत जान पड़ता है। पहली पंक्ति में ‘बगुलों-सी वृद्धाएँ’ में उपमा अलंकार है। कवि ने तत्सम शब्दों का प्रयोग करके अपनी बात को बहुत सुंदर रूप में चित्रित किया है।

8. आशय स्पष्ट कीजिए-

(क) ताम्रपर्ण, पीपल से, शतमुख/ झरते चंचल स्वर्णिम निर्झर!

उत्तर

पीपल के सूखे पत्ते ऐसे लग रहे हैं मानो ताँबे धातु से बने हों। वह पेड़ से गिरते हुए ऐसे लग रहे हैं मानो सैंकड़ों मुँह वाले झरनों से सुनहरे रंग की धाराएँ गिर रही हों।

(ख) दीप शिखा-सा ज्वलित कलश/नभ में उठकर करता नीराजन!

उत्तर

मंदिर के शिखर पर लगा कलश सूर्य की रोशनी के प्रभाव से दीपक की जलती लौ के समान लग रहा है। ऐसा लग रहा है मानो संध्या आरती में वह भी लोगों के समान आरती कर रहा है।

(ग) सोन खगों की पाँति/आर्द्र ध्वनि से नीरव नभ करती मुखरित!

उत्तर

आकाश में व्याप्त खग नामक पक्षी पंक्ति में उड़ रहे हैं। उनकी गुंजार शांत आकाश को गुंजार से भर देती है।

(घ) मन से कढ़ अवसाद श्राति / आँखों के आगे बुनती जाला!

उत्तर

मनुष्य के मन में व्याप्त दुख तथा कष्ट उसकी आँखों में यादों के रूप में उभर आते हैं।

(ङ) क्षीण ज्योति ने चुपके ज्यों / गोपन मन को दे दी हो भाषा!

उत्तर

घरों में विद्यमान दीपक जल उठे हैं। इस अंधकार में उसकी रोशनी अवश्य कमज़ोर है। उस कमज़ोर ज्योति ने लगता है गोपों के मन को एक आशा दे दी है।

(च) बिना आय की क्लाति बन रही/ उसके जीवन की परिभाषा!

उत्तर

गाँव में लोगों के पास आय का साधन विद्यमान नहीं है। अतः उसके जीवन में बहुत दुख विद्यमान हैं। ऐसा लगता है कि मानो यह अभाव उसकी कहानी बनकर रह जाएँगे।

(छ) व्यक्ति नहीं, जग की परिपाटी/ दोषी जन के दुःख क्लेश की।

उत्तर

दोष से युक्त सामाजिक व्यवस्था ही मनुष्य के दुख का कारण है। धन के असमान बँटवारे के कारण ही समाज में अंतर व्याप्त है।

Read More

Chapter 13 पद्माकर | class 11th | Ncert solution for Hindi Antra

NCERT Solutions for Class 11th: पाठ 13 – पद्माकर

प्रश्न अभ्यास

1. पहले छंद में कवि ने किस ऋतु का वर्णन किया है?

उत्तर

पद्माकर ने पहले छंद में बसंत ऋतु का प्रभावशाली वर्णन किया है।

2. इस ऋतु में प्रकृति में क्या परिवर्तन होते हैं?

उत्तर

इस ऋतु में प्रकृति में ये परिवर्तन होते हैं-
• वसंत ऋतु में वृक्षों के झुंडों में भँवरे गुंजार करने लगते हैं।
• बगीचों में विभिन्न रंगों के फूल खिलने लगते हैं।
• आम का बौर अपनी सुगंध से सारे वातावरण को मादक बना देता है।
• पक्षी के समूह शोर मचाने लगते हैं।
• वनस्पतियाँ रस-रंग से परिपूर्ण हो जाती हैं।
• युवावर्ग आनंद में झूमने लगता है|

3. ‘और’ की बार-बार आवृत्ति से अर्थ में क्या विशिष्टता उत्पन्न हुई है?

उत्तर

कवि ने अपने कवित्त में ‘और’ शब्द की आवृत्ति से प्रकट किया है कि ऋतुराज वसंत का प्रभाव तो अति विशिष्ट है; बिलकुल अलग प्रकार का है, वैसा प्रभाव तो किसी ऋतु का हो ही नहीं सकता। प्रकृति तथा लोगों में वसंत ऋतु के आने पर मन में जो चमत्कारी बदलाव हुआ है, इस शब्द के माध्यम से उसे दिखाने में कवि सफल हो पाए हैं| इस शब्द से पता चलता है कि अभी जो प्राकृतिक सुंदरता थी उसमें और भी वृद्धि हुई है।

4. ‘पद्माकर के काव्य में अनुप्रास की योजना अनूठी बन पड़ी है।’ उक्त कथन को प्रथम छंद के आधार पर स्पष्ट कीजिए।

उत्तर

पद्माकर ने अनुप्रास अलंकार का सहज-स्वाभाविक प्रयोग तो किया ही है| उन्होंने स्थान-स्थान पर अनुप्रास का ऐसा प्रयोग किया है कि उनकी योजना अनूठी बन गई है। इसके उदाहरण इस प्रकार हैं-
(क) भीर भौंर
(ख) छलिया छबीले छैल और छबि छ्वै गए
(ग) गोकुल के कुल के गली के गोप गाउन के
(घ) कछू-को-कछू भाखत भनै
(ङ) चलित चतुर
(च) चुराई चित चोराचोरी
(छ) मंजुल मलारन
(ज) छवि छावनो

5. होली के अवसर पर सारा गोकुल गाँव किस प्रकार रंगों के सागर में डूब जाता है? दूसरे छंद के आधार पर लिखिए।

उत्तर

गोकुल की गलियों में सभी लोग होली के रंगों में डूबकर किसी को कुछ भी कह देते हैं। गोपों द्वारा घरों के आगे-पीछे दौड़कर होली खेली जा रही है। होली का हुड़दंग मचा हुआ है। एक गोपी कृष्ण के प्रेम के स्याम रंग में भीगी हुई है। वह इसे हटाना नहीं चाहती है, बस इसी में डूबना चाहती है। किसी को किसी का लिहाज़ नहीं है। कोई भी कुछ भी सुनना नहीं चाहता है। उनके विषय में कुछ भी कहना संभव नहीं है।

6. ‘बोरत तौं बोर्यो पै निचोरत बनै नहीं’ इस पंक्ति में गोपिका के मन का क्या भाव व्यक्त हुआ है?

उत्तर

इस पंक्ति में गोपी कहती हैं कि मैं तो कृष्ण के रंग में चोरी-चोरी रंग गई हूँ अर्थात मैंने सबसे चोरी अपने मन को कृष्ण के रंग में रंग दिया है। एक बार अपना मन कृष्ण के रंग में रंग देने के पश्चात अब मैं उसे निचोड़ने यानी उससे मुक्त होने के लिए तैयार नहीं हूँ।

7. पद्माकर ने किस तरह भाषा शिल्प से भाव-सौंदर्य को और अधिक बढ़ाया है? सोदाहरण लिखिए।

उत्तर

पद्माकर भाषा शिल्प में माहिर थे। उन्होंने अपना सारा काव्य ब्रजभाषा में रचा है जिसमें अलंकारों की अधिकता है। सूक्ष्म अनुभूतियों को दिखाने के लिए लाक्षणिक शब्द का इस्तेमाल किया गया है। उदाहरण के लिए यह उदाहरण देखें-
औरै भाँति कुंजन में गुंजरत भीर भौंर,
औरे डौर झौरन पैं बौरन के ह्वै गए।
‘औरै’ शब्द की पुनरुक्ति चमत्कार उत्पन्न देती है। अनुप्रास अलंकार के प्रयोग के जो ध्वनिचित्र बने हैं, वे अद्भुत हैं। उदाहरण के लिए देखिए-
1. छलिया छबीले छैल औरे छबि छ्वै गए
2. गोकुल के कुल के गली के गोप गाउन के
इसी कवित्त में ‘बोरत तौँ बोर्यो पै निचोरत बनीं नहीं’ में विशेषोक्ति अलंकार है। ‘होली वर्णन’ के पद में कवि ने चाक्षुक बिंब का आकर्षक विधान किया है तथा ‘हौं तो स्याम-रंग में चुराई चित चोरा चोरी’ में अनुप्रास तथा ‘स्याम-रंग’ में श्लेष अलंकार का सहज भाव से प्रयोग किया गया है।

8. तीसरे छंद में कवि ने सावन ऋतु की किन-किन विशेषताओं की ओर ध्यान आकर्षित किया है?

उत्तर

सावन ऋतु की विशेषताएँ इस प्रकार हैं-
• बगीचे में भँवरों का स्वर फैल गया है। उनका गुंजार मल्हार राग के समान प्रतीत होता है।
• इस ऋतु के प्रभाव से ही अपना प्रिय प्राण से अधिक प्यारा लगता है।
• मोर की ध्वनि हिंडोलों की छवि-सी लगती है।
• यह प्रेम की ऋतु है।
• झूले झूलने के लिए यह सर्वोत्तम ऋतु है।

9. संदर्भ सहित व्याख्या कीजिए-

(क) औरै भाँति कुंजन”…..”छबि छ्वै गए।

उत्तर

प्रसंग- प्रस्तुत पंक्ति प्रसिद्ध कवि पद्माकर द्वारा रचित है। इसमें कवि वसंत ऋतु में बाग-बगीचों में होने वाले परिवर्तन को दर्शा रहे हैं।

व्याख्या- प्रस्तुत पंक्तियों में वसंत ऋतु के आने पर वातावरण की विशेषता बताई गई है। पद्माकर कहते हैं कि बाग में भवरों के समूहों की भीड़ बढ़ गई है। बागों में आम के पेड़ों पर बौरें लग गई हैं। इससे पता चलता है कि फल अब लगने ही वाले हैं। भाव यह है कि वसंत ऋतु में बाग में फूल खिलने लगते हैं, जिसके कारण भवरों की संख्या में वृद्धि हो गई है। ऐसे ही आम के वृक्षों पर बौरें लग गई हैं, जो इस बात का प्रमाण है कि फल लगने वाले हैं।

(ख) तौ लौं चलित “बनै नहीं।

उत्तर

प्रसंग- प्रस्तुत पंक्ति प्रसिद्ध कवि पद्माकर द्वारा रचित है। इसमें एक गोपी की दशा का वर्णन किया गया है। उस पर श्याम रंग चढ़ गया है और वह उसे उतारना नहीं चाहती है।

व्याख्या- पद्माकर कहते हैं कि होली खेलते समय एक गोपी कहती हैं कि मेरे पर कृष्ण का रंग चढ़ गया है। दूसरी सखी उसे इस रंग को निचोड़कर उतारने के लिए कहती है। वह गोपी इस रंग को उतारना नहीं चाहती है। यह रंग कृष्ण के प्रेम का रंग है। वह कहती है कि यदि वह इस रंग को निचोड़ देगी, तो यह रंग निकल जाएगा। वह इस रंग में डूब जाना चाहती है। अतः वह दूसरी गोपी को मना कर देती है। भाव यह है कि जो कृष्ण से प्रेम करता है, वह उसके रंग को अपना लेता है। गोपी भी कृष्ण को प्रेम करती है। अतः कृष्ण से प्रेम करने के कारण कृष्ण का काला रंग भी उसे अच्छा लगता है।

(ग) कहैं पद्माकर…”लगत है।

उत्तर

प्रसंग- प्रस्तुत पंक्ति प्रसिद्ध कवि पद्माकर द्वारा रचित है। प्रस्तुत पंक्ति में पद्माकर वर्षा ऋतु की विशेषता बता रहे हैं। उनके अनुसार यह प्रेम की ऋतु है और इसमें रूठना-मनाना अच्छा लगता है।

व्याख्या- पद्माकर कहते हैं कि वर्षा ऋतु में प्रेमिका को अपना प्रियमत अच्छा लगता है। इसमें रूठे प्रेमी को मनाने में भी आनंद आता है। भाव यह है कि प्रायः जब प्रियतम रूठ जाता है, तो मनुष्य अहंकार वश मनाता नहीं है। वर्षा ऋतु में यदि प्रेमी नाराज़ हो जाए, तो उसे मनाना अच्छा लगता है। यह ऋतु का ही प्रभाव है कि नाराज़ प्रेमी को मनाकर आनंद प्राप्त किया जाता है।

Read More

Chapter 8: Communication Open Source Concept | NCERT Solution for class 12th COMPUTER SCIENCE


NCERT Solutions for Class 12 Computer Science (C++) – Networking and Open Source Concepts

TOPIC-1
Communication Technoiogies

Very Short Answer Type Questions [1 mark each]

Question 1:
Identify the Domain name and URL from the following :
http://www.income.in/home.aboutus.hml
Answer:
Domain name – income.in
URL – http://www.income.in/home.aboutus.hml

Question 2:
What is Web Hosting?
Answer:
Web hosting is the service that makes our website available to be viewed by others on the Internet. A web host provides space on its server, so that other computers around the world can access our website by means of a network or modem.

Question 3:
What is the difference between packet & message switching ?
Answer:

Packet SwitchingMessage switching
There is a tight upper limit on the block size. A fixed size of packet is specified.In message switching there was no upper limit.
All the packets are stored in main memory in switching office.In message switching packets are stored on disk. This increases the performance as access time is reduced.

Question 4:
Which protocol in used in creating a connection with a remote machine ?
Answer:
Telnet : It is an older internet utility that allow us to log on to remote computer system. It also facilitates for terminal emulation purpose.

Question 5:
Which protocol is used to create a connection with a remote machine? Give any two advantage of using Optical Fibers.
Answer:
Telnet Two advantage of using Optical Fibers are

  1. Capable of extremely high speed.
  2. No Electromagnetic interference.
  3. Extremely low attending

Question 6:
What is cloud computing ?
Answer:
The sharing of computer resources (dedicated, time-shared, or dynamically shared servers) and related infrastructurer components (load balancers, firewalls, network storage, developer tools, monitors and management tools) to facilitate the deployment and operation of web and network based applications. Cloud computing relies on sharing of resources to achieve coherence and economies of scale, similar to a utility (like the electricity grid) over a network.

Question 7:
Write two characterstics of Wi-Fi.
Answer:

  1. It is wireless network.
  2. It is for short range.

Question 8:
Expand the following :

  1. GSM
  2. GPRS

Answer:

  1. GSM – Global System for Mobile Communication.
  2. GPRS – General Packet Radio Service.

Question 9:
Which type of network out of LAN, PAN and MAN is formed, when you connect two mobiles using Bluetooth to transfer a video
Answer:
PAN

Question 10:
Write one characterstic each for 2G and 3G mobile technologies.
Answer:
2G networks primarily involve the transmission of voice information while 3G technology provides the additional advantage of data transfer.

Question 11:
What is the difference between Packet switching and circuit switching techniques ?
Answer:
In circuit switching, a dedicated path exists from source to destination while in packet switching, there is no fixed path.

Question 12:
Write two advantages of using an optical fibre cable over an Ethernet cable to connect two service stations, which are 200 m away from each other.
Answer:
Advantages of optical fibre :

  1. Faster speed than ethernet
  2. Lower Attenuation

Question 13:
Write one advantage of bus topology of network. Also illustrate how four (4) computers can be connected with each other using bus topology of network.
Answer:
Advantage (benefits) of Linear Bus Topology is that the cable length required for this topology is the least compared to the other networks.
Bus Topology of Network:
ncert-solutions-for-class-12-computer-science-c-networking-and-open-source-concepts-(198-1)

Question 14:
Give one suitable example of each URL and Domain Name.
Answer:
URL: http://waltons.in
Domain Name: gmail.com

Question 15:
Write one advantage of star topology of network ? Also, illustrate how five (5) computers can be connected with each other using star topology of network.
Answer:
Advantage (benefits) of star toplogy:
Easy to replace, install or remove hosts or other devices.
ncert-solutions-for-class-12-computer-science-c-networking-and-open-source-concepts-(198-2)

Question 16:
Identify the type of topology on the basis of the following :
(a) Since every node is directly connected to the server, a large amount of cable is needed which increases the installation cost of the network.
(b) It has a single common data path connecting all the nods.
Answer:
(a) Star Topology
(b) Bus Topology

Question 17:
Expand the following :
(a) VOIP
(b) SMTP
Answer:
(a) Voice Over Internet Protocol
(b) Simple Mail Transfer Protocol

Question 18:
Daniel has to share the data among various computers of his two offices branches situated in the same city. Name the network (out of LAN, WAN, PAN and MAN) which is being formed in this process.
Answer:
MAN

Question 19:
ABC International School is planning to connect • all computers, each spread over a distance of 50 metres. Suggest an economic cable type having high speed data transfer to connect these computers.
Answer:
Optical Fibre Cable.

Question 20:
Mahesh wants to transfer data within a city at very high speed. Write the wired transmission medium and type of network.
Answer:
Wired transmission medium – Optical fibre cable Type of network – MAN.

Question 21:
Which device is used to connect all computers inside a lab ?
Answer:
Hub or Switch

Question 22:
Which device is used to connect all computers to the internet using telephone wire ?
Answer:
RJ – 45. It is an eight wired connectors used to connect computers on a LAN.

Question 23:
What is Wi-Fi Card ?
Answer:
Wi-Fi cards are small and portable cards that allow the computer to connect to the internet through a wireless network. The transmission is through the use of radio waves.

Question 24:
Explain the purpose of a router.
Answer:
A router establishes connection between two network and it can handle network with different protocols. Using a routing table, routers make sure that the data packets are travelling through the best possible paths to reach their destination.

Question 25:
Identify the type of topology from the following.
(a) Each node is connected with the help of a single cable
(b) Each node is connected with the help of independent cable with central switching.
Answer:
(a) Bus topology
(b) Star topology

Question 26:
What is the difference between LAN and MAN ?
Answer:
LAN : It is Local Area Network. The diameter is not more than a single building.
WAN : It is Metropolitan Area Network. LAN spans a few kms while MAN spans 5-50 km diameter and is larger than a WAN.

Short Answer Type Questions-I [2 marks each]

Question 1:
Write any 1 advantage and 1 disadvantage of Bus topology.
Answer:
Advantage : Since there is a single common data path connecting all the nodes, the bus topology uses a very short cable length which considerably reduces the installation cost. Disadvantage : Fault detection and isolation is difficult. This is because control of the network is not centralized in any particular node. If a node is faulty on the bus, detection of fault may have to be performed at many points on the network. The faulty node has then to be rectified at that connection point.

Question 2:
SunRise Pvt. Ltd. is setting up the network in the Ahmedabad. There are four departments named as MrktDept, FinDept, LegalDept, SalesDept.
ncert-solutions-for-class-12-computer-science-c-networking-and-open-source-concepts-(199-1)
Distance between varioud buldings is as given:

MrktDept to FinDept80 m
MrktDept to LegalDept180 m
MrktDept to SalesDept100 m
LegalDept to SalesDept150 m
LegalDept to FinDept100 m
FinDept to SalesDept50 m

Number of Computers in the buildings :

MrktDept20
LegalDept10
FinDept08
SalesDept42

(i) Suggest a cable layout of connections between the Departments and specify the topology.
ncert-solutions-for-class-12-computer-science-c-networking-and-open-source-concepts-(200-1)
Star Topology should be used.
(ii) Suggest the most suitable building to place the server by giving suitable reason.
Answer:
As per 80 – 20 rule, server should be placed in MrktDept because it has maximium no. of computers.
(iii) Suggest the placement of (i) modem (ii) Hub/ Switch in the network.
Answer:
Each building should have hub/switch and moderm in case Internet connection is required.
(iv) The organization is planning to link its sale counter situated in various part of the same city, which type of network out of LAN, WAN, MAN will be formed ? Justify.
Answer:
MAN (Metropolitan Area Network) as MAN network can be carried out in a city network.

Question 3:
Name the protocol
(i) Used to transfer voice using packet switched network.
Answer:
VAns.VOIP (Voice Over Internet Protocol)
(ii) Used for chatting between 2 group or between 2 individuals.
Answer:
IRC (Internet Relay Chat)

Question 4:
What is an IP Address ?
Answer:
IP address is a unique identifier for a node or host connection on an IP network. An IP address is a 32 bit binary number usually represented as 4 decimal values, each representing 8 bits, in the range 0 to 255 (know as octets) separated by decimal points. This is known as “dotted decimal” notation.
Example : 140.179.220.200

Question 5:
What is HTTP ?
Answer:
HTTP is a protocol that is used for transferring hypertext (i.e., text,graphic,image,sound,video,e tc,) between 2 computers and is particularly used on the world wideWeb (WWW).
[1 mark for definition/explanation]

Question 6:
Explain the importance of Cookies.
Answer:
When the user browses a website, the web server sends a text file to the web browser. This small text file is a cookie. They are usually used to track the pages that we visit so that information can be customised for us for that visit.

Question 7:
How is 4G different from 3G?
Answer:
3G technology adds multimedia facilities such as video, audio and graphics applications whereas 4G will provide better than TV quality images and video-links.

Question 8:
Illustrate the layout for connecting 5 computers
in a Bus and a Start topology of Networks.
Answer:
Bus topology
ncert-solutions-for-class-12-computer-science-c-networking-and-open-source-concepts-(200-2)
Or any valid illustration of Bus and Star Topology.

Question 9:
What is a spam mail ?
Answer:
Spam is the abuse of electronic messaging systems (including most broadcast media, digital delivery systems) to send unsolicited bulk messages indiscriminately.

Question 10:
Differentiate between FTP and HTTP
Answer:
FTP is a protocol to transfer files over the Internet
HTTP is a protocol which allows the use of HTML to browse web pages in the World Wide Web.

Question 11:
Answer:
following, which is the fastest

  1. wired and
  2. wireless medium of communication ?

Answer:

  1. Wired – Optical Fiber
  2. Wireless – Infrared OR Microwave

Question 12:
What is Worm ? How is it removed ?
Answer:
A worm is a self-replicating computer program. It uses a network to send copies of itself to other computers on the network and it may do so without any user intervention.
Most of .the common anti-virus (anti-worm) remove worm.

Question 13:
Out of the following, which all comes under cyber crime ?
(i) Stealing away a brand new computer from a showroom.
(ii) Getting in someone’s social networking account without his consent and posting pictures on his behalf to harash him.
(iii) Secretly copying files from server of a call center and selling it to the other organization.
(iv) Viewing sites on a internet browser.
Answer:
(ii) & (iii)

Question 14:
Perfect Edu Services Ltd. is an educational organization. It is planning to setup its India campus at Chennai with its head office at Delhi. The Chennai campus has 4 main buildings – ADMIN, ENGINEERING, BUSINESS and MEDIA. [O.D, 2015]
You as a network expert have to suggest the best network related solutions for their problems raised in (i) to (iv), keeping in mind the distances between the buildings and other given parameters.
ncert-solutions-for-class-12-computer-science-c-networking-and-open-source-concepts-(201-1)
Shortest distances between various buildings.

ADMIN To ENGINEERING55 m
ADMIN to BUSINESS90 m
ADMIN to MEDIA90 m
ENGINEERING to BUSINESS55 m
ENGINEERING to MEDIA90 m
BUSINESS to MEDIA45 m
DELHI Head Office to CHENNAI Campus2175 km

Number of Computers Installed at various buildings are as follows :

ADMIN110
ENGINEERING75
BUSINESS40
MEDIA12
DELHI Head Office20

(i) Suggest the most appropriate location of the server inside the Chennai campus (out of the 4 buildings), to get the best connectivity for maximum no. of computers. Justify your answer.
Answer:
ADMIN (Due to maximum number of computers)
OR
Media (Due to shorter distance from the other buildings)
(ii) Suggest and draw the cable layout to efficiently connect various buildings within the Chennai Campus for connecting the computers.
Answer:
Anyone of the following
ncert-solutions-for-class-12-computer-science-c-networking-and-open-source-concepts-(201-2)
ncert-solutions-for-class-12-computer-science-c-networking-and-open-source-concepts-(202-1)
(iii) Which hardware device will you suggest to be procured by the company to be installed to protect and control the internet uses within the campus ?
Answer:
Firewall OR Router
(iv) Which of the following will you suggest to establish the online face-to-face communication between the people in the Admin Office of Chennai Campus and Delhi Head Office ?
Answer:
Cable TV

Question 15:
What kind of data gets stored in cookies and how is it useful ?
Answer:
When a Website with cookie capabilities is visited, its server sends certain information about the browser, which is stored in the hard drive as a text file. It is as way for the server to remember things about the visited sites.

Question 16:
Differentiate between packet switching over message switching ?
Answer:
Packet Switching : Follow store and forward principle for fixed packets. Fixes an upper limit for packet size.
Message Switching : Follows store and forward principle for complete message. No limit on block size.

Question 17:
Out of the following, which is the fastest
(i) wired and
(ii) wireless medium of communication ?
Infrared, Coaxial Cable, Ethernet Cable, Microwave, Optical Fiber
Answer:
(i) Wired : Optical Fiber
(ii) Wireless : Infrared OR Microwave

Question 18:
What is Trojan Horse ?
Answer:
A Trojan Horse is a code hidden in a program, that looks safe but has hidden side effects typically causing loss or theft of data, and possible system harm.

Question 19:
Out of the following, which all comes under cyber crime ?

  1. Stealing away a brand new hard disk from a showroom.
  2. Getting in someone’s social networking account without his consent and posting on his behalf.
  3. Secretly copying data from server of an organization and selling it to tire other organization.
  4. Looking at online activities of a friends blog.

Answer:
(ii) & (iii)

Question 20:
Write any two differences between twisted pair and coaxial pair cable.
Answer:

Twisted PairCo-axial Cable
Their bandwidth is not as high as coaxial cables.It has high bandwidth.
A twisted pair consists of two copper wires twisted around each other (each has its own insulation around it) like a double helix.A coaxial cable consists of a copper wire core covered by an insulating material and a layer of conducting material over that.

Question 21:
Write one advantage of Bus Topology of network, also, illustrate how 4 computers can be connected with each other using star topology of network.
Answer:
Cable length required for his topology is the least compared to other networks.
OR
Any other correct advantage of Bus Topology of network.
Illustration of 4 computers connected with each other using star topology of network.
ncert-solutions-for-class-12-computer-science-c-networking-and-open-source-concepts-(202-2)

Short Answer Type Question-II [3 marks]

Question 1:
Uplifting Skills Hub India is a knowledge and skill community which has an aim to uplift the standard of knowledge and skills in the society. It is planning to setup its training centres in multiple towns and villages pan India with its head offices in the nearest cities. They have created a model of their network with a city, a town and 3 villages as follows.
As a network consultant, you have to suggest the best network related solutions for their issues/problems raised in (i) to (iv) keeping in mind the distance between various locations and given parameters.
ncert-solutions-for-class-12-computer-science-c-networking-and-open-source-concepts-(203-1)
Shortest distance between various location :

VILLAGE 1 to B_TOWN2 KM
VILLAGE 2 to B_TOWN1.0 KM
VILLAGE 3 to B_TOWN1.5 KM
VILLAGE 1 to VILLAGE 23.5 KM
VILLAGE 1 to VILLAGE 34.5 KM
VILLAGE 2 to VILLAGE 32.5 KM
A CITY Head Office to B HUB25 KM

Number of Computers installed at various locations are as follows :

B_TOWN120
VILLAGE 115
VILLAGE 210
VILLAGE 315
A_CITY OFFICE6

Note :

• In Villages, there are community centres, in which one room has been given as training center to this organization to install computers.
• The organization has got financial support from the government and top IT companies.

  1. Suggest the most appropriate location of the SERVER in the BHUB (out of the 4 locations), to get the best and effective connectivity. Justify your answer.
  2. Suggest the best wired medium and draw the cable layout (location to location) to efficiently connect various locations within the B HUB.
  3. Which hardware device will you suggest to connect all the computers within each location of B_HUB ?
  4. Which service/protocol will be most helpful to conduct live interactions of Experts from Head Office and people at all locations of B HUB ?

Answer:
(i) B-TOWN can house the server as it has the maximum no. of computers.
(ii) Optical fibre cable is the best for this star topology.
ncert-solutions-for-class-12-computer-science-c-networking-and-open-source-concepts-(203-2)
(iii) Switch
(iv) VoIP

Long Answer Type Questions [4 marks each]

Question 1:
Indian School in Mumbai is starting up the network between its different wings. There are Four Buildings named as SENIOR, JUNIOR, ADMIN and HOSTEL as shown below.:
ncert-solutions-for-class-12-computer-science-c-networking-and-open-source-concepts-(203-3)
The distance between various buildings is as follows:

ADMIN TO SENIOR200m
ADMIN TO JUNIOR150m
ADMIN TO HOSTEL50m
SENIOR TO JUNIOR250m
SENIOR TO HOSTEL350m
JUNIOR TO HOSTEL350m

Number of Computers in Each Building :

SENIOR130
JUNIOR80
ADMIN160
HOSTEL50

(b1) Suggest the cable layout of connections between the buildings.
(b2) Suggest the most suitable place (i.e., building) to house the server of this school, provide a suitable reason.
(b3) Suggest the placement of the following devices with justification, i Repeater i Hub/Switch
(b4) The organisation also has inquiry office in another dty about 50-60 km away in hilly region. Suggest the suitable transmission media to interconnect to school and inquiry office out of the following : i Fiber optic cable, i Microwave, i Radiowave
Answer:
(b1)

ncert-solutions-for-class-12-computer-science-c-networking-and-open-source-concepts-(204-1)

(b2) Server can be placed in the ADMIN building as it has the maxium number of computer.
(b3) Repeater can be placed between ADMIN and SENIOR building as the distance is more than 110 m.
(b4) Radiowaves can be used in hilly regions as they can travel through obstacles.

Question 2:
Vidya Senior Secondary Public School in Nainital is setting up the network between its different wings. There are 4 wings named as SENIOR(S), JUNIOR(J), ADMIN(A) and HOSTEL(H).
Distance between various wings are given below :

Wing A to Wing S100 m
Wing A to Wing J200 m
Wing A to Wing H400 m
Wing S to Wing J300 m
Wing S to Wing H100 m
Wing J to Wing H450 m
WingNumber of Computers
Wing A
Wing S
Wing J
Wing H
20
150
50
25

(ii) Name the most suitable wing where the Server should be installed. Justify your answer.
(iii) Suggest where all Hub(s)/Switch(es) should be placed in the network.
(iv) Which communication medium would you suggest to connect this school with its main branch in Delhi ?
Answer:
(i) Star Topology

ncert-solutions-for-class-12-computer-science-c-networking-and-open-source-concepts-(204-2)

(ii) Server should be in Wing S as it has the maximum number of computers.
(iii) All Wings need hub/switch as it has more than one computer.
(iv) Since the distance is more, wireless transmission would be better. Radiowaves are reliable and can travel through obstacles

Question 3:
Trine Tech Corporation (TTC) is a professional consultancy company. The company is planning to set up their new offices in India with its hub at Hyderabad. As a network adviser, you have to understand their requirement and suggest them the best available solutions. Their queries are mentioned as (i) to (iv) below.
Physical Locations of the blocks of TTC


ncert-solutions-for-class-12-computer-science-c-networking-and-open-source-concepts-(204-3)

Block to Block distances (in Mtrs.)

Block (From)Block (To)Distance
Human ResourceConference110
Human ResourceFinance40
ConferenceFinance80

Expected Number of Computers to be installed in each block

BlockComputers
Human Resource
Finance
Conference
25
120
90
  1. What will be the most appropriate block, where TTC should plan to install their server?
  2. Draw a block diagram showing cable layout to connect all the buildings in the most appropriate manner for efficient communication.
  3. What will be the best possible connectivity out of the following, you will suggest to connect the new setup of offices in Bangalore with its London based office.
    • Satellite Link
    • Infrared
    • Ethernet Cable
  4. Which of the following device will be suggested by you to connect each computer in each of the buildings?
    • Switch
    • Modem
    • Gateway

Answer:
(i) Finance block because it has maximum number of computers.
(ii)

ncert-solutions-for-class-12-computer-science-c-networking-and-open-source-concepts-(205-1)

(iii) Satellite link
(iv) Switch

Question 4:
Tech Up Corporation (TUC) is a professional consultancy company. The company is planning to set up their new offices in India with its hub at Hyderabad. As a network adviser, you have to understand their requirement and suggest them the best available solutions. Their queries are mentioned as (i) to (iv) below.
Physical Locations of the blocks of TUC

ncert-solutions-for-class-12-computer-science-c-networking-and-open-source-concepts-(205-2)
Block to Block distances (in Mtrs.)

Block (From)Block (To)Distance
Human ResourceConference60
Human ResourceFinance120
ConferenceFinance80

Expected Number of Computers to be installed in each block

BlockComputers
Human Resource
Finance
Conference
25
120
90
  1. What will be the most appropriate block, where TUC should plan to install their server?
  2. Draw a block to block cable layout to connect all the buildings in the most appropriate manner for efficient communication.
  3. What will be the best possible connectivity out of the following you will suggest to connect the new setup of offices in Bangalore with its London based office?
    • Infrared
    • Satellite Link
    • Ethernet Cable
  4. Which of the following devices will be suggested by you to connect each computer in each of the buildings?
    • Gateway
    • Switch
    • Modem

Answer:
(i) Human resource block because it has maximum number of computers.
(ii)
ncert-solutions-for-class-12-computer-science-c-networking-and-open-source-concepts-(205-3)
(iii) Satellite link
(iv) Switch

Question 5:
G.R.K International Inc. is planning to connect its Bengaluru Office Setup with its Head Office in Delhi. The Bengaluru Office G.R.K. inter-national Inc. is spread across and area of approx. 1 square kilometer, consisting of 3 blocks – Human Resources, Academics and Administration.
You as a network expert have to suggest answers to the four queries (i) to (iv) raised by them.
Note : Keep the distance’ between blocks and no. of computers in each block in mind, while providing them the solutions.

ncert-solutions-for-class-12-computer-science-c-networking-and-open-source-concepts-(205-4)

Shortest distances between various blocks :

Human Resources to Administration100 m
Human Resources to Academics65 m
Academics to Administration110 m
Delhi Head Office to Bengaluru Office Setup2350 km

Number of Computers installed at various blocks are as follows:

BLOCKNo. of Computers
Human Resources155
Administration20
Academics100
Delhi Head Office20
  1. Suggest the most suitable block in the Bengaluru Office Setup, to host the server. Give a suitable reason with your suggestion.
  2. Suggest the cable layout among the various blocks within the Bengaluru Office Setup for connecting the Blocks.
  3. Suggest a suitable networking device to be installed in each of the blocks essentially required for connecting computers inside the blocks with fast and efficient connectivity.
  4. Suggest the most suitable media to provide secure, fast and reliable data connectivity between Delhi Head Office and the Bengaluru Office Setup.

Answer:

(i) Human Resources because it has maximum number of computers.
(ii)

ncert-solutions-for-class-12-computer-science-c-networking-and-open-source-concepts-(206-1)
(iii) Switch
(iv) Satellite link

Question 6:
Rovenza Communications International (RCI) is an online corporate training provider company for IT related courses. The company is setting up their new campus in Kolkata. You as a network expert have to study the physical locations of various blocks and the number of computers to be installed. In the planning phase, provide the best possible answers for the queries (i) to (iv) raised by them.
ncert-solutions-for-class-12-computer-science-c-networking-and-open-source-concepts-(206-2)
Block to Block Distances (in Mtrs.)

FromToDistance
Administrative Block
Administrative Block
Finance Block
Finance Block Faculty
Recording Block Faculty
Recording Block
60
120
70

Expected Computers to be installed in each block

BlockComputers
Administrative Block
Finance Block
Faculty Recording Block
30
20
100
  1. Suggest the most appropriate block, where RCI should plan to install the server.
  2. Suggest the most appropriate block to block cable layout to connect all three blocks for efficient communication.
  3. Which type of network out of the following is formed by connecting the computers of these three blocks?
    • LAN
    • MAN
    • WAN
  4. Which wireless channel out of the following should be opted by RCI to connect to students from all over the world?
    • Infrared
    • Microwave
    • Satellite
  5. Write two advantages of using open source software over proprietary software.
  6. Which of the following crime(s) does not come under cybercrime ?
    1. Copying some important data from a computer without taking permission from the owner of-the data.
    2. Stealing keyboard and mouse from a shop.
    3. Getting into unknown person’s social networking account and start messaging on his behalf.

Answer:
(i) Faculty Recording Block.
(ii) Bus Topology
ncert-solutions-for-class-12-computer-science-c-networking-and-open-source-concepts-(206-3)
(iii) LAN
(iv) Satellite connection
(v) Advantages of open source over proprietary software :
• Open source software’s source code is available, can be modified copied & distributed while propritary software can’t be change.
• Open source is free while propriatary is paid.
(vi) (ii) Stealing keyboard & mouse from-a shop.

Question 7:
(a) What is the difference between domain name and IP address?
(b) Write two advantages of using an optical fibre cable over an Ethernet cable to connect two sendee stations, which are 190 m away from each other.
(c) Expertia Professsional Global (EPG) is an online, corporate training provider company for IT related courses. The company is setting up their new campus in Mumbai. You as a network expert have to study the physical locations of various buildings and the number of computers to be installed. In the planning phase, provide the best possible answer for the queries (i) to (iv) raised by them.
ncert-solutions-for-class-12-computer-science-c-networking-and-open-source-concepts-(207-1)
Building to Building Distances (in Mtrs.)

FromToDistance
Administrative Building
Administrative Building
Finance Building
Finance Building
Recording Studio Building
Faculty Studio Building
60
120
70

Expected Computers to be installed in each Building:

BuildingComputers
Administrative Building
Finance Building
Faculty Studio Building
20
40
120
  1. Suggest the most appropriate building, where EPG should plan to install the server.
  2. Suggest the most appropriate building to building cable layout to connect all three buildings for efficient communication.
  3. Which type of network out of the following is formed by connecting the computers of these three buildings?
    • LAN
    • MAN
    • WAN
  4. Which wireless channel out of the following should be opted by EPG to connect to students of all over the world?
    • Infrared
    • Microwave
    • Satellite

Answer:
(a) Domain Name is alphanumeric address of a resource over network IP address is a Numeric Address of a resoure in a Network. Example :
Domain Name
WWW.Gabsclasses.com
IP Address
102.112.0.153
(b) Optical fibre Advantages :
(i) Faculty Studio Building.
(ii) Bus Topology.
Faculty Finance
Administrative Building
Studio Building
(iii) LAN
(iv) Satellite

Question 8:
To provide telemedicine faculty in a hilly state, a computer network is to be setup to connect hospitals in 6 small villages (VI, V2, …, V6) to the base hospital (H) in the state capital. This is shown in the following diagram.
ncert-solutions-for-class-12-computer-science-c-networking-and-open-source-concepts-(207-2)
No village is more than 20 km away from the state capital.
Imagine yourself as a computer consultant for this project and answer the following questions with justification :

  1. Out of the following what kind of link should be provided to setup this network :
    1. Microwave link,
    2. Radio Link,
    3. Wired Link ?
  2. What kind of network will be formed; LAN, MAN, or WAN ?
  3. Many times doctors at village hospital will have to consult senior doctors at the base hospital. For this purpose, how should they contact them: using email, sms, telephone, or video conference ?
  4. Out of SMTP and POP3 which protocol is used to receive emails ?
  5. What are cookies in the context of computer networks?
  6. Rajeshwari is trying for on-line subscription to a magazine. For this she has filled in a form on the magazine’s web site. When the clicks submit button she gets a message that she has left e-mail field empty and she must fill it. For such checking which type of script is generally executed; client side script or server-side script ?
  7. Mention any one difference between free-ware and free software.

Answer:
(i) Radio Link
(ii) MAN
(iii) e-mail
(iv) POP3
(v) Cookies are files that store user information that is used to identify the user when he logs into the system.
(vi) Server-side script.
(vii) Freeware is a software that has the user to get unlimited usage. Free software may be free for a certain period’only.

Question 9:
Work a lot Consultants are setting up a secured network for their office campus at Gurgaon for their day-to-day office and web- based activities. They are planning to have connectivity between three buildings and the head office situated in Mumbai. Answer the questions (i) to (iv) after going through the building positions in the campus and other details, which are given below:
ncert-solutions-for-class-12-computer-science-c-networking-and-open-source-concepts-(208-1)
Distances between various buildings :

Building “GREEN” to Building “RED”110 m
Building “GREEN” to Building “BLUE”45 m
Building “BLUE” to Building “RED”65 m
Gurgaon Campus to Head Office1760 km

Number of computers

Building “GREEN”32
Building “RED”150
Building “BLUE”45
Head Office10
  1. Suggest the most suitable place (i.e., building) to house the server of this organization. Also give a reason to justify your suggested location.
  2. Suggest a cable layout of connections between the buildings inside the campus.
  3. Suggest the placement of the following devices with justification:
    1. Repeater.
    2. Switch.
  4. The organization is planning to provide a high speed link with its head office situated in Mumbai using a wired connection. Which of the following cables will be most suitable for this job ?
    1. Optical Fibre
    2. Coaxial Cable
    3. Ethernet Cable

Answer:
(i) The most suitable place to install server is building “RED” because this building has maximum computer which reduce communication delay.
(ii) Cable layout is Bus topology
ncert-solutions-for-class-12-computer-science-c-networking-and-open-source-concepts-(208-2)
(iii) Since the cabling distance between buildings GREEN, BLUE and RED are quite large, so a repeater, would ideally be needed along their path to avoid loss of signals during the course of data flow in there routes.
ncert-solutions-for-class-12-computer-science-c-networking-and-open-source-concepts-(208-3)
(2) In the layout a switch each would be needed in all the building, to interconnect the group of cables from the different computers in each building.
ncert-solutions-for-class-12-computer-science-c-networking-and-open-source-concepts-(209-1)
(iv) Optical fibre.

Question 10:
Granuda Consultants are setting up a secured network for their office campus at Faridabad for their day to day office and web based activities. They are planning to have connectivity between 3 building and the head office situated in Kolkata. Answer the questions (i) to (iv) after going through the building positions in the campus and other details, which are given below :
ncert-solutions-for-class-12-computer-science-c-networking-and-open-source-concepts-(209-2)
Distances between various buildings :

Building “RAVI” to Building “JAMUNA”120 m
Building “RAVI” to Building “GANGA”50 m
Building “GANGA” to Building “JAMUNA”65 m
Faridabad Campus to Head Office1460 km

Number of computers

Building “RAVI”25
Building “JAMUNA”150
Building “GANGA”51
Head Office10
  1. Suggest the most suitable place (i.e., block) to house the server of this organization. Also give a reason to justify your suggested location.
  2. Suggest a cable layout of connections between the buildings inside the campus.
  3. Suggest the placement of the following devices with justification:
    1. Repeater
    2. Switch
  4. The organization is planning to provide a high speed link with its head office situated in the KOLKATA using a wired connection. Which of the following cable will be most suitable for this job ?
    1. Optical Fibre
    2. Coaxial Cable
    3. Ethernet Cable

Answer:
(i) The most suitable place to install server is in building “JAMUNA” because this building has maximum computer which reduce the communication delay.
(ii) Cable layout. (Bus topology).
ncert-solutions-for-class-12-computer-science-c-networking-and-open-source-concepts-(209-3)
(iii) (1) Since the cabling distance between buildings RAVI, GANGA and JAMUNA are quite large, so a repeater, would ideally be needed along their path to avoid loss of signals during the course of data flow in these routes.
ncert-solutions-for-class-12-computer-science-c-networking-and-open-source-concepts-(209-4)
(2) In the layout a switch would be needed in all the building, to interconnect the group of cables from the different computers in each building.
ncert-solutions-for-class-12-computer-science-c-networking-and-open-source-concepts-(210-1)
(iv) Optical fibre.

Question 11:
Rehaana Medicos Center has set up its new center in Dubai. It has four buildings as shown in the diagram given below :
ncert-solutions-for-class-12-computer-science-c-networking-and-open-source-concepts-(210-2)
Distances between various buildings are as follows:

Accounts to Research Lab55 m
Accounts to Store150 m
Store to Packaging Unit160 m
Packaging Unit to Research Lab60 m
Accounts to Packaging Unit125 m
Store to Research Lab180 m

Number of computers

Accounts25
Research Lab100
Store15
Packaging Unit60

As a network expert, provide the best possible answer for the following queries :

  1. Suggest a cable layout of connections between the buildings.
  2. Suggest the most suitable place (i.e. buildings) to house the server of this origanization.
  3. Suggest the placement of the following device with justification :
    (a) Repeater
    (b) Switch/Hub
  4. Suggest a system (hardware/sofware) to prevent unauthorized access to or from the network.

Answer:
(i) Layout 1
ncert-solutions-for-class-12-computer-science-c-networking-and-open-source-concepts-(210-3)
(ii) The most suitable place/building to house the server of this organization would be in Research Lab, building as this building contains the maximum number of computers.
(iii) (a) For layout I, since the cabling distance between Accounts to Store is quite large, so a repeater would ideally be needed along their path to avoid loss of signals during the course of data flow in this route. For layotat2, since the cabling distance between Store to Research Lab is quite large, so a repeater would ideally be placed.
(b) In both the layouts, a Flub/Switch each would be needed in all the buildings to interconnect the group of cables from the different computers in each building.
(iv) Firewall

Question 12:
Who is a hacker ?
Answer:
A computer enthusiast, who uses his computer . programming skills to intentionally access a computer without authorization is known as hacker. A hacker accesses the computer without the intention of destorying data or maliciously harming the computer.

Question 13:
The following is a 32 bit binary number usually represented as 4 decimal values, each representing 8 bits, in the range 0 to 255 (know as octets) separated by decimal points. 140.179.220.200
What is it? What is its importance?
Answer:
It is an IP Address. It is used to identify the computers on a network.

TOPIC-2
Network Security and Web Service

Very Short Answer Type Questions [1 mark each]

Question 1:
Define firewall.
Answer:
A system designed to prevent unauthorized access to or from a private network is called firewall. It can be implemented in both hardware and software or combination of both.

Question 2:
Write any two examples of Server side Scripts.
Answer:

  1. ASP
  2. PHP

Question 3:
What is the difference between E-mail & chat?
Answer:

  1. Chat occurs in near real time, while E-mail doesn’t.
  2. Chat is a 2-way communication which require the permission of both parties, while E-mail is a 1-way communication.

Question 4:
Write names of any two popular open source software, which are used as operating systems.
Answer:

  1. Kernels
  2. Unix
  3. Linux

Question 5:
What is the difference between video conferencing and chat.
Answer:
In conference, we can include more than one person and it allows text, video and audio while chat is one-to-one communication.

Question 6:
Expand the following abbreviations :

  1. HTTP
  2. VOIP

Answer:

  1. HTTP-Hyper Text Transfer Protocol.
  2. VOIP-Voice Over Internet Protocol.

Question 7:
What is the difference between HTTP and FTP?
Answer:
Hyper Text Transfer Protocol deals with Transfer of Text and Multimedia content over internet while FTP (File Transfer Protocol) deals with transfer of files over the internet.

Question 8:
What out of the following, will you use to have an audio-visual chat with an expert sitting in a far-away place to fix-up a technical issue ?

  1. VOIP
  2. Email
  3. FTP

Answer:
(i) VOIP

Question 9:
Name one server side scripting language and one client side scripting language.
Answer:
Client Side :

  1. JAVASCRIPT
  2. VBSCRIPT

Server Side :

  1. ASP
  2. JSP

Question 10:
Which out of the following comes under cyber crime ?

  1. Operating someone’s internet banking account, without his knowledge.
  2. Stealing a keyboard from someone’s computer.
  3. Working on someone’s Computer with his/ her permission.

Answer:
(i) Operating someone’s internet banking account, without his knowledge.

Question 11:
Name two proprietary softwares along with their application.
Answer:

  1. MS-Office – All office applications MS-Word, MS-Excel, MS-PowerPoint.
  2. Visual Studio – Visual Basic, Visual C+ + softwares for application development.

Question 12:
Name some cyber offences under the IT Act.
Answer:

  1. Tampering with computer source documents
  2. Hacking.
  3. Publishing of information which is obscene in electronic form.

Question 13:
What are the 3 ways of protecting intellectual property ?
Answer:

  1. Patents
  2. Copyrights
  3. Trademark

Question 14:
When a user browses a website, the web server sends a text file to the web browser. What is the name of this ?
Answer:
Cookies.

Short Answer Type Questions – I [2 mark each]

Question 1:
Define the following :

  1. Firewall
  2. VoIP

Answer:
(i) Firewall : A system designed to prevent unauthorized access to or from a private network is called firewall. It can be implemented in both hardware and software or combination of both.
(ii) VoIP : Voice -over-Internet Protocol(VoIP) is a methodology and group of technologies for delivering voice communications and multimedia sessions over Internet Protocol(IP) networks, such as the Internet.

Question 2:
Give the full form of the following terms.

  1. XML
  2. FLOSS
  3. HTTP
  4. FTP

Answer:

  1. XML: Extensible Markup Language.
  2. FLOSS: Free-Libre Open Source Software.
  3. HTTP: Hyper Text Transfer Protocol.
  4. FTP: File Transfer Protocol.

Question 3:
Differentiate between WORM and VIRUS in Computer terminology.
Answer:
VIRUS directly effects the system by corrupting the useful data. A computer virus attaches itself to a program or file enabling it to spread from one computer to another.
A worm is similar to a virus by design and is considered to be sub class of a virus. Worm spread from computer to computer, but unlike a virus, it has the capability to travel without any human action.

Abbrevations :
Question 4:
Expand the following

  1. GSM
  2. GPRS.

Answer:

  1. GSM : Global System for Mobile Communication.
  2. GPRS : General Packet Radio Service.

Question 5:
Expand the following abbreviations :

  1. HTTP
  2. VOIP

Answer:

  1. HTTP : Hyper Text Transfer Protocol.
  2. VOIP : Voice Over Internet Protocol.

Question 6:
Give the full form of :

  1. FOSS
  2. HTTP

Answer:

  1. FOSS : Free Open Source Software.
  2. HTTP : Hyper Text Transfer Protocol.

Question 7:
Write the full forms of the following :

  1. GNU
  2. XML

Answer:

  1. GNU : GNU’s Not Unix
  2. XML : Extensible Markup Language.

Question 8:
Expand the following terminologies :

  1. GSM
  2. WLL

Answer:

  1. GSM : Global System for Mobile Communication
  2. WLL : Wireless Local Loop.

Question 9:
Give the full forms of the following terms :

  1. CDMA
  2. TDMA
  3. FDMA

Answer:

  1. CDMA : Code Division Multiple Access
  2. TDMA : Time Division Multiple Access
  3. FDMA : Frequency Division Multiple Access

Question 10:
Expand the following abbreviations :

  1. FTP
  2. TCP
  3. SMTP
  4. VOIP

Answer:

  1. FTP : File Transfer Protocol
  2. TCP : Transmission Control Protocol.
  3. SMTP : Simple Mail Transfer Protocol.
  4. VOIP : Voice Over Internet Protocol.

Short Answer Type Questions-II [3 marks each]

Question 1:
Give two examples of PAN and LAN type of networks.
Answer:

PANLAN
(i) Personal Area Network
(ii) Spans a few meters
Example :
Bluetooth using 2 moblies and laptops sharing files.
(i) Local Area Network
(ii) Spans upto a km.
Example :
System in a lab in a school, systems at home.

Question 2:
Which protocol helps us to browse through web pages using internet browsers ? Name any one internet browser.
Answer:
HTTP
Google Chrome is a browser

Question 3:
Write two advantages of 4G over 3G Mobile Telecommunication Technologies in terms of speed and services.
Answer:
4G has very high data rates upto 100 Mbps.
It covers a wider lange than 3G

Question 1:
Write two characteristics of Web 2.0
Answer:
Web 2.0

  1. dynamic and interactive websites
  2. Only the changed part is reloaded so faster
Read More

Chapter 7: Boolean Algebra | NCERT Solution for class 12th COMPUTER SCIENCE

NCERT Solutions for Class 12 Computer Science (C++) – Boolean Algebra

TOPIC-1
Basics of Boolean Algebra

Very Short Answer Type Questions    [1 mark each]

Question 1:
Which gates are known as universal gates ? Why?
Аnswer:
Universal gates are the ones which can be used for implementing any gate like AND, OR and NOT or any combination of these basic gates. NAND and NOR gates are universal gates.

Question 2:
Draw the equivalent logic circuit for the following Boolean expression :
Аnswer:
ncert-solutions-class-12-computer-science-c-boolean-algebra-(178-1)

Question 3:
Express the OR operator in terms of AND and NOT operator.
Аnswer:
(A . B)’ = \(\overline { A }\) + \(\overline { B }\)
(\(\overline { A }\) + \(\overline { B }\))’ = A + B

Question 4:
Specify which axioms/theorems are being used in the following Boolean reductions :
(a) (be)’ + be = 1
(b) xyz + zx = xz
Аnswer:
(a) x + x’ = 1 & Complementary law
(b) y + x = x & Absorption law.

Question 5:
State and verify Associative law using Truth Table.
Аnswer:
Associative Law: This law states that:
(A + B) + C = A + (B + C)
(A.B).C = A. (B.C)
Proof:
ncert-solutions-class-12-computer-science-c-boolean-algebra-(178-2)
∴ From above truth table,
(A + B) + C = A + (B + C)
Similarly, we can prove,
A. (B.C) = (A. B).C
ncert-solutions-class-12-computer-science-c-boolean-algebra-(179-1)

Short Answer Type Questions-I    [2 mark each]

Question 1:
Correct the following boolean statements :
1. X+1 = X
2. (A’)’ = A’
3.  A+A’ = 0
4.  (A+B)’ = A.B
Аnswer:
1. X+l=l or X+0=X
2. ((A’)’) = A
3. A + A’ = 1 or A. A’ = 0
4. (A 4- B)’ = A’.B1

Question 2:
Write the POS form of a Boolean Function F, which is represented in a truth table as follows :
ncert-solutions-class-12-computer-science-c-boolean-algebra-(179-2)
Аnswer:
(P+Q+R).(P’+Q+R).(P’+Q’+R)

Short Answer Type Questions-II  [3 mark each]

Laws and Theorems
Question 1:
State and Verify Absorption law algebraically.
Аnswer:
Absorption law states that :
A + AB = A and A. (A + B) = A
Algebraic method :
Taking LHS
A + AB = (A.l) + (A.B) by Identity
= A. (1 + B) by Distribution
= A.l by Null Element
= A

Question 2:
State and define principle of duality. Why is it so important in Boolean Algebra ?
Аnswer:
Principle of duality : Duality principle states that from every boolean relation another boolean relation can be derived by :
(i) Changing each OR sign (+) to an AND sign (-).
(ii) Changing each AND sign (-) to an OR sign (+)
ex : Dual of A + A’B = A. (A’ + B)
Importance in Boolean Algebra : The principle of duality is an important concept in Boolean algebra, particularly in proving various theorems. The principle of duality is used extensively in proving Boolean algebra theorem. Once we prove that an expression is valid, by the principle of duality, its dual is also valid. Hence, our effort in proving various theorems is reduced to half.

Question 3:
Name the law shown below & verify it using a . truth table.
X+ \(\overline { X }\).Y = X + Y.
Аnswer:
This law is called “Absorption Law” also referred as redundance law.
ncert-solutions-class-12-computer-science-c-boolean-algebra-(180-1)

Question 4:
Draw a logic circuit for the following Boolean expression : ab + c.d’.
Аnswer:
ncert-solutions-class-12-computer-science-c-boolean-algebra-(180-2)

Question 5:
Write the SOP form of a Boolean function F, which is represented in a truth table as follows :
ncert-solutions-class-12-computer-science-c-boolean-algebra-(180-3)
Аnswer:
A’B’C + A’BC + AB’C + AB’C

Question 6:
Draw the Logic Circuit for the following Boolean Expression :
(U + V). w + z
Аnswer:
ncert-solutions-class-12-computer-science-c-boolean-algebra-(180-4)

Question 7:
Verify the following using Boolean Laws :
LT + V = LTV + LP.V + U.V
Аnswer:
L.H.S.
= U’ + V
= U’ . (V + V) + V (LP + U)
= U’ . V + LP . V + U . V + U. V
= U’. V + LP. V + U. V
= R.H.S.

OR

R.H.S.
= U’V’ + U’. V + U. V
= LP . (V + V) + U. V
= U’ 1 + U.V
= U’ + U.V
= U’ +V
= L.H.S.

Question 8:
Draw the Logic Circuit for the following Boolean Expression :
(X’ + Y). Z + W’
Аnswer:
ncert-solutions-class-12-computer-science-c-boolean-algebra-(180-5)

Question 9:
Write the equivalent boolean expression for the following logic circuit.
ncert-solutions-class-12-computer-science-c-boolean-algebra-(180-6)
Аnswer:
((X’.Y)’ + (X.Y’)’)’

Question 10:
Write the equivalent Boolean Expression for the. following Logic Circuit :
ncert-solutions-class-12-computer-science-c-boolean-algebra-(180-7)
Аnswer:
Z = (A+B)(B’ +C)
= A.B’ + AC + B.B’ + BC
= A.B’ + AC + BC

Question 11:
Obtain the Boolean Expression for the logic circuit shown below :
ncert-solutions-class-12-computer-science-c-boolean-algebra-(181-1)
Аnswer:
F = \(\left( \overline { A } .B \right) +\left( \overline { C+\overline { D } }\right)\)
= \(\left( \overline { A } .B \right) +\overline { C } .D\)

Question 12:
Name the law shown below & verify it using a truth table.
A + B . C = (A + B). (A + C).
Аnswer:
This law is called “Distributive Law”.
Prove by Truth table
ncert-solutions-class-12-computer-science-c-boolean-algebra-(181-2)

Question 13:
Obtain the Boolean Expression for the logic circuit shown below :
ncert-solutions-class-12-computer-science-c-boolean-algebra-(181-3)
Аnswer:
F = ( X.\(\overline { Y }\) ) + ( \(\overline { Z }\) + W).
F = \(\overline { X }\) + Y + \(\overline { Z }\) + W.

Question 14:
State Demorgan’s law. Verify one of them using truth table.
Аnswer:
There are two Demorgan’s law :
(i)  \(\overline { A.B }\) = \(\overline { A }\) + \(\overline { B }\)
(ii)  \(\overline { A+B }\) = \(\overline { XA}\) . \(\overline { B }\)
Proof :
(i)  \(\overline { A.B }\) = \(\overline { A }\) + \(\overline { B }\)

ncert-solutions-class-12-computer-science-c-boolean-algebra-(181-4)

Question 15:
Draw a logic Circuit for the boolean expression:
A . \(\overline { B }\) + (C + \(\overline { B }\)). \(\overline { A }\)
Аnswer:
ncert-solutions-class-12-computer-science-c-boolean-algebra-(181-5)

Question 16:
Obtain the Boolean Expression for the logic circuit shown below :
ncert-solutions-class-12-computer-science-c-boolean-algebra-(181-6)
F = P’ Q + (Q + R’)
= Q. (P’ + R’)

Question 17:
Verify the following using Boolean Laws X + Z = X + X’. Z + Y. Z
Аnswer:
Taking RHS
X + X’Z + YZ
= (X + X’). (X + Z) + YZ (Distribution Law)
= 1. (X + Z) + YZ    (A + A’ = 1)
= X + Z + YZ
= X + Z (1 + Y)
= X + Z    (1 + A = 1; 1. A = A)
= Hence verified

Question 18:
Verify the following using Boolean Laws : A + C = A + A. C + B.C
Аnswer:
A + C = A + A’.C + BC
Solve RHS
A + A’C + BC
(A + A). (A + C) + BC [Using distributive law]
1. (A + C) + BC
= A + C + BC
= A + C(1 + B)
= A + C.1
= A + C
= LHS (Hence, verified)

Question 19:
Obtain the Boolean Expression for the logic circuit shown below :
ncert-solutions-class-12-computer-science-c-boolean-algebra-(182-1)
Expression at F :
( \(\overline { X }\) . Y) + (Y + \(\overline { Z }\) )
( \(\overline { X }\) + 1) Y + \(\overline { Z }\)    [Distributive law]
Y + \(\overline { Z }\)    [ ∴ 1 + Z = 1]

Question 20:
Verify the following using truth table :
(i) X . X’ = 0
(ii) X + 1 = 1
Аnswer:
ncert-solutions-class-12-computer-science-c-boolean-algebra-(182-2)

Question 21:
Write the equivalent boolean expression for the following logic circuit :
ncert-solutions-class-12-computer-science-c-boolean-algebra-(182-3)
Аnswer:
Y = U \(\overline { V }\) + \(\overline { U}\) \(\overline { W }\)

Question 22:
Write the equivalent boolean expression for the following logic circuit :
ncert-solutions-class-12-computer-science-c-boolean-algebra-(182-4)
Аnswer:
Y = (U + \(\overline { V }\) ). (U + \(\overline { W }\) )

Question 23:
Verify the following using truth table :
(i) X + 0 = X
(ii) X + X’ = 1
Аnswer:
ncert-solutions-class-12-computer-science-c-boolean-algebra-(182-5)
ncert-solutions-class-12-computer-science-c-boolean-algebra-(182-6)

Question 24:
Derive a Canonical SOP expression for a Boolean function F, represented by the following truth table :
ncert-solutions-class-12-computer-science-c-boolean-algebra-(182-7)
Аnswer:
F(A, B, C) = A’B’C + A’BC + AB’C + ABC
OR
F(A,B,C) =∑(0, 3,4,7)

Question 25:
Derive a Canonical POS expression for a Boolean function F, represented by the following truth table :
ncert-solutions-class-12-computer-science-c-boolean-algebra-(182-8)
Аnswer:
F(RQ,R) = (P+Q+R’)(P+Q,+R)(P’+Q,+R’) (P’+Q’+R)
OR
F(RQ,R)=II(1,2,5,6)

Question 26:
Obtain a simplified form for a Boolean expression :
F(U, V, W, Z) = II (0,1,3,5, 6, 7,15)
Аnswer:
ncert-solutions-class-12-computer-science-c-boolean-algebra-(183-1)
(u + v + w).(u+z’).(v’+w’).(u’+w’+z)

Question 27:
Reduce the following Boolean Expression to its simplest form using K-Map :
F (X, X Z, W) = X (0,1, 6, 8, 9,10,11,12,15)
Аnswer:
ncert-solutions-class-12-computer-science-c-boolean-algebra-(183-2)
ncert-solutions-class-12-computer-science-c-boolean-algebra-(183-3)
Simplified Expression : XY + Y’Z’ + XZ’W’ + XZW + X’YZW’

Question 28:
Reduce the following Boolean Expression to its simplest form using K-Map :
F(X, Y, Z, W) = X (0,1,4, 5,6, 7,8, 9,11,15)
Аnswer:
ncert-solutions-class-12-computer-science-c-boolean-algebra-(183-4)
ncert-solutions-class-12-computer-science-c-boolean-algebra-(184-1)
Simplified Expression : Y’Z’ + XY + XZW

Question 29:
Verify the following using Boolean Laws.
X + Y’ = X. Y + X. Y + X’. Y
Аnswer:
L. H. S.
= X + Y’
= X. (Y+Y’) + (X + X’). Y’
= X. Y + X. Y’ + X. Y’ + X’. Y’
= X. Y + X. Y’ + X’. Y’
= R. H. S
OR
= X. Y + X. Y’ + X’. Y’
= X. (Y + Y’) + X’. Y’
= X. 1 + X’. Y’
= X + X’. Y’
= X + Y
= L. H. S

Question 30:
State Distributive law and verify it using truth table.
Аnswer:
Distributive law : This law states that
(i) x(y + z) = xy + x.z.
(ii) x + yz = (x + y)(x + z)
ncert-solutions-class-12-computer-science-c-boolean-algebra-(184-2)

Question 31:
Reduce the following Boolean Expression using KMap :
F(A, B, C, D) = ∑{0,1,3, 5, 6, 7,9,11,13,14,15}
Аnswer:
ncert-solutions-class-12-computer-science-c-boolean-algebra-(184-3)
A’B’C’+D+BC

TOPIC-2
Karnaugh Map Minimization and Applications of Boolean Algebra

Very Short Answer Type Questions [1 mark each]

Question 1:
Write Product of Sum expression of the function F (a, b, c, d) from the given truth table
ncert-solutions-class-12-computer-science-c-boolean-algebra-(186-1)
Аnswer:
F (a, b, c, d) =
(a + b + c + d).(a + b + c + d’). (a + b’ + c + d) . (a + b’ + c’ + d’). (a’ + b + c + d).
(a’ + b + c + d’). (a’ + b’ + c + d). (a’ + b’ + c + d’) . (a’ + b’ + c’ + d)

Question 2:
Convert the following boolean expression inti! its equivalent Canonical Sum of Products form (SOP) :
(U + V + W) (U + V + W’) (U’ + V + W) (U’ + V’ + W’)
Аnswer:
π (0,1, 4, 7)
∑(2, 3, 5, 6)
010 011 101 110
= U’VW’ + U’VW + UV’W + UVW’

Question 3:
Write the Sum of Product form of the function F(R Q, R) for the following truth table representation of F :
ncert-solutions-class-12-computer-science-c-boolean-algebra-(186-2)

Question 4:
Write the Product of Sum form of the function F(X, Y, Z) for the following truth table representation of F :
ncert-solutions-class-12-computer-science-c-boolean-algebra-(186-3)

Question 5:
Write the Product of Sum form of the function G(U, V W) for the following truth table representation of G :
ncert-solutions-class-12-computer-science-c-boolean-algebra-(186-4)

Question 6:
Write the Product of Sum form of function G(U, V, W) for the following truth table representation of G :
ncert-solutions-class-12-computer-science-c-boolean-algebra-(186-5)
ncert-solutions-class-12-computer-science-c-boolean-algebra-(187-1)

Question 7:
Write the Sum of Product form of the function F(A, B, C) for the following truth table reprsentation of
ncert-solutions-class-12-computer-science-c-boolean-algebra-(187-2)
ncert-solutions-class-12-computer-science-c-boolean-algebra-(187-3)
SOP = A’BC’ + A’BC + AB’C’ + ABC

Question 8:
Write the SOP form of a boolean function F, which is represented in a truth table as follows:
ncert-solutions-class-12-computer-science-c-boolean-algebra-(187-4)
Аnswer:
F(X, Y, Z) = X’.Y’. Z’ + X’. Y. Z’ + X. Y’. Z’+ X.Y.Z

Question 9:
Write the POS form of boolean function G, which is represented in a truth table as follows :
ncert-solutions-class-12-computer-science-c-boolean-algebra-(187-5)
Аnswer:
G (A, B, C) = (A + B + C). (A + B’ + C’). (A’ + B + C). (A’ + B + C’)

Short Answer Type Questions-II

Question 1:
Obtain the minimal SOP form for the following Boolean expression using K-Map.
F(A,B,C,D) = ∑ (0,2,3,5,7,8,10,1143,15)
Аnswer:
ncert-solutions-class-12-computer-science-c-boolean-algebra-(187-6)
Quad 1 = m0 + m2 + m8 + m10 = B’D’
Quad 2 = m3 + m7 + m15 + m11 = CD
Quad 3 = m5 + m7 + m15 + m13 = BD
Minimal SOP = B’D’ + CD + BD

Question 2:
Reduce the following Boolean expression using
K-Map :
F(A,B,C,D) = 7r (0,1,2,4,5,6,8,10)
Аnswer:
ncert-solutions-class-12-computer-science-c-boolean-algebra-(188-1)
F(A, B, C, D) = π(0,1,2,4, 5, 6,8,10) F = (A + C).(A + D).(B + D)

Question 3:
Reduce the following using K-Map :
F (A, B,C,D) = ∑(1,3,4,5,6,7,12,13)
Аnswer:
ncert-solutions-class-12-computer-science-c-boolean-algebra-(188-2)

Question 4:
Reduce the following boolean expression using
K-map.
F(EQ,R,S) = 2(0,2,4,5,6,7,8,10,13,15).
Аnswer:
\(\overline { P }\) Q + \(\overline { Q }\)\(\overline { S }\) + QS.
ncert-solutions-class-12-computer-science-c-boolean-algebra-(188-3)

Question 5:
Reduce the following Boolean Expression using K-Map :
F(P, Q, R, S) = ∑(1,2, 3,4,5, 6, 7, 8,10)
Аnswer:
ncert-solutions-class-12-computer-science-c-boolean-algebra-(188-4)
F(P, Q, R, S) = P’Q + P’S + P’R’S’ + PQ’S’

Question 6:
Reduce the following Boolean Expression using
K-Map :
F (A, B, C, D) = ∑(2, 3,4,5, 6, 7,8,10,11)
ncert-solutions-class-12-computer-science-c-boolean-algebra-(188-5)
F (A, B, C, D) = A’B + A’C + B’C + ABD’

Long Answer Type Questions [4 marks each]

Question 1:
Verify the following using Boolean Laws :
[Delhi, 2016]
A ‘ + B’ . C=A’ . B ‘ . C ‘ + A’ . B . C ‘ + A’ .B.C + A’ .B’ .C+ A.B’ .C
Аnswer:
A’+ B’C = A’B’C’ + A,BCI + A’BC’ + A’BC + A’B’C + ABC
=A’C'(B’+B)+A’C (Grouping)
(B+B’)+AB’C
=> A’C’+ A’C + AB’C
(x+x’y=x+y)
=> A’ (C+C’ ) +AB’ C
=> A’+AB’C
(x+x’=1)
=> A’+B’C
X=A’ y=B’C
= LHS
Hence Proved.

Question 2:
Write the Boolean Expression for the result of the Logic Circuit as shown below :
ncert-solutions-class-12-computer-science-c-boolean-algebra-(189-1)
Аnswer:
F = (u+v’).(u+w).(v+w’)

Question 3:
Derive a Canonical POS expression for a Boolen function F, represented by the following truth table :
ncert-solutions-class-12-computer-science-c-boolean-algebra-(189-2)
Аnswer:
F = ∑(0, 3,4,5)
= (P + Q + R) (P + Q’ + R’) (P’ + Q + R) (P’ + Q + R’)

Question 4:
Reduce the following Boolean Expression to its simplest form using K-Map :
F (X, Y, Z, W)
∑(2,6,7,8,9,10,11,13,14,15)
Аnswer:
∑(2,6,7,8,9,10,11,13,14,15)
ncert-solutions-class-12-computer-science-c-boolean-algebra-(189-3)
F = XY’ + ZW’+ XW + YZ

Question 5:
Write the Boolean Expression for the result of the Logic Circuit as shown below :
ncert-solutions-class-12-computer-science-c-boolean-algebra-(189-4)
Аnswer:
G = PQ’ + PR + QR’

Question 6:
Derive a Canonical SOP expression for a Boolean function G, represented by the following truth table :
ncert-solutions-class-12-computer-science-c-boolean-algebra-(189-5)
Аnswer:
G = ∑{(0,2,6,7)
= A’B’C’ + A’BC’ + ABC’ + ABC

Question 7:
Verify the following using Boolean Laws :
X’+ Y’Z = X’ .Y’ .Z’+X’ .Y.Z’+X’ .Y.Z+X’ .Y’ .Z + X.Y’.Z.
Аnswer:
X ‘+Y’ Z=X ‘ Y ‘ Z ‘ +X ‘ YZ ‘ +X ‘ YZ+X ‘ Y ‘ Z+XY ‘ Z
Taking RHS
Grouping terms
=> x’Z’ (Y’+Y)+X’ Z(Y+Y’)+XY’Z
=> X’Z’+X’Z+XY’Z
(Y+Y’=1)
=> X'(Z’+Z)+XY’Z
(Grouping)
=> X’+XY’Z (Z+Z’=l)
=> X’+Y’Z (Substitute X=X’ Y=Y’Z X+X’ Y = X+Y)
= LHS

Read More

Chapter 6: Database & SQL | NCERT Solution for class 12th COMPUTER SCIENCE

Class 12 Computer Science Chapter 6: Database & SQL



• Database is a collection of related tables. MySQL is a ‘relational’ DBMS.

• DDL (Data Definition Language) includes SQL statements such as, Create table, Alter table and Drop table.

• DML (Data Manipulation Language) includes SQL statements such as, insert, select, update and delete.

• A table is a collection of rows and columns, where each row is a record and columns describe the feature of records.

• ALTER TABLE statement is used to make changes in the structure of a table like adding, removing or changing datatype of column(s).

• UPDATE statement is used to modify existing data in a table.

• WHERE clause in SQL query is used to enforce condition(s).

• DISTINCT clause is used to eliminate repetition and display the values only once.

• The BETWEEN operator defines the range of values inclusive of boundary values.

• The IN operator selects values that match any value in the given list of values.

• NULL values can be tested using IS NULL and IS NOT NULL.

• ORDER BY clause is used to display the result of a SQL query in ascending or descending order with respect to specified attribute values. By default the order is ascending.

• LIKE operator is used for pattern matching. % and _ are two wild card characters. The per cent (%) symbol is used to represent zero or more characters. The underscore (_) symbol is used to represent a single character.

• A Function is used to perform a particular task and return a value as a result.

• Single Row functions work on a single row of the table and return a single value.

• Multiple Row functions work on a set of records as a whole and return a single value. Examples include COUNT, MAX, MIN, AVG and SUM.

• GROUP BY function is used to group rows of a table that contain the same values in a specified column.

• Join is an operation which is used to combine rows from two or more tables based on one or more common fields between them.


1. Answer the following questions:

a) Define RDBMS. Name any two RDBMS software.

Answer: RDBMS stands for Relational Database Management System. An RDBMS is a DBMS designed especially for relational databases, which provide the facility to store and manage large amount of data. It allows to store the data in structured format using rows and columns.

Two RDBMS Software are – MySQL, Oracle

b) What is the purpose of the following clauses in a select statement?

i) ORDER BY

ii) GROUP BY

Answer     (i) ORDER BY – ORDER BY clause is used with SELECT statement, to arranges the result of an SQL query in either ascending or descending on the basis of particular columns (fields).

(ii) GROUP BY – The GROUP BY clause is used in SELECT statement, to divide the table into groups i.e combines all records that have identical values in a particular field.

Grouping can be done by a common column name or with aggregate functions in which case the aggregate produces a value for each.

For example :

mysql> SELECT GENDER, COUNT(*) FROM STUDENT GROUP BY GENDER;

OUTPUT:

GENDER COUNT(*)

MALE 20

FEMALE 15


c) Site any two differences between Single-row functions and Aggregate functions.

Answer   : Single Row Functions and Aggregate Functions

  • Single Row Function applied on the each row while Aggregate Functions applied on the group of rows.
  • Single Row Functions return multiple output i.e. output based on each row while Aggregate function returns only one result i.e. output based on group of rows.

d) What do you understand by Cartesian Product?

Answer : A Cartesian product combines the tuples of one relation with all the tuples of the other relation. It is created when two tables are joined without any join condition.

e) Differentiate between the following statements :

i) ALTER and UPDATE ii) DELETE and DROP

i) ALTER and UPDATE

Answer : The ALTER TABLE is a DDL command used to make changes in the structure of a table, such as, adding or deleting a column, modifying the definition of a column, adding / deleting / modifying constraints. It can also used to RENAME the table.

The UPDATE is a DML command used to modify the data stored in a table, such as modifying records or updating records.

ii) DELETE and DROP

Answer : DELETE is a DML command, which is used to remove tuples / records from a table. Delete command will delete only records not a table.

DROP is a DDL command, which is used to remove table, database and views. It deletes entire table including records.

If DROP is used with ALTER TABLE command then it is use to delete/remove column, constraint.


f) Write the name of the functions to perform the following operations:

i) To display the day like “Monday”, “Tuesday”, from the date when India got independence.

Answer :  DAYNAME( )

ii) To display the specified number of characters from a particular position of the given string.

Answer :  MID( ) or SUBSTRING( )

iii) To display the name of the month in which you were born.

Answer :  MONTHNAME( )

iv) To display your name in capital letters.

Answer :  UCASE( ) or UPPER( )


2. Write the output produced by the following SQL commands:

a) SELECT POW(2,3);

sql pow function

b) SELECT ROUND(123.2345, 2), ROUND(342.9234,-1);

c) SELECT LENGTH(“Informatics Practices”);

d) SELECT YEAR(“1979/11/26”), MONTH(“1979/11/26”), DAY(“1979/11/26”), MONTHNAME(“1979/11/26”);

e) SELECT LEFT(“INDIA”,3), RIGHT (“Computer Science”,4);

f) SELECT MID(“Informatics”,3,4), SUBSTR(“Practices”,3);



3. Consider the following MOVIE table and write the SQL queries based on it.

MovieIDMovieNameCategoryReleaseDateProductionCostBusinessCost
001Hindi_MovieMusical2018-04-23124500130000
002Tamil_MovieAction2016-05-17112000118000
003English_MovieHorror2017-08-06245000360000
004Bengali_MovieAdventure2017-01-0472000100000
005Telugu_MovieActionNULL100000NULL
006Punjabi_MovieComedyNULL30500NULL

Table : Movie

a) Display all the information from the Movie table.

Answer : SELECT * FROM MOVIE;

b) List business done by the movies showing only MovieID, MovieName and Total_Earning. Total_Earning to be calculated as the sum of ProductionCost and BusinessCost.

Answer : SELECT MovieID, MovieName, ProductionCost + BusinessCost as “Total_Earning” FROM MOVIE;

c) List the different categories of movies.

Answer : SELECT DISTINCT Category FROM MOVIE;

OR

SELECT DISTINCT(Category) FROM MOVIE;

d) Find the net profit of each movie showing its MovieID, MovieName and NetProfit. Net Profit is to be calculated as the difference between Business Cost and Production Cost.

Answer : SELECT MovieID, MovieName, BusinessCost – ProductionCost as “Net Profict” FROM MOVIE;

e) List MovieID, MovieName and Cost for all movies with ProductionCost greater than 10,000 and less than 1,00,000.

Answer : SELECT MovieID, MovieName, ProductionCost FROM MOVIE WHERE ProductionCost > 10000 and ProductionCost < 100000;

f) List details of all movies which fall in the category of comedy or action.

Answer : SELECT * FROM MOVIE WHERE Category IN (‘Comedy’, ‘Action’);

g) List details of all movies which have not been released yet.

Answer : SELECT * FROM MOVIE WHERE ReleaseDate IS NULL;

4. Suppose your school management has decided to conduct cricket matches between students of Class XI and Class XII. Students of each class are asked to join any one of the four teams – Team Titan, Team Rockers, Team Magnet and Team Hurricane. During summer vacations, various matches will be conducted between these teams. Help your sports teacher to do the following:

a) Create a database “Sports”.

Answer : CREATE DATABASE Sports;

b) Create a table “TEAM” with following considerations:

i) It should have a column TeamID for storing an integer value between 1 to 9, which refers to unique identification of a team.

ii) Each TeamID should have its associated name (TeamName), which should be a string of length not less than 10 characters.

Answer : CREATE TABLE TEAM (TeamID INTEGER CHECK (TeamID BETWEEN 1 AND 9), TeamName VARCHAR(30) CHECK(Length (TeamName) >= 10) )

c) Using table level constraint, make TeamID as the primary key.

Answer : CREATE TABLE TEAM (TeamID INTEGER CHECK (TeamID BETWEEN 1 AND 9), TeamName VARCHAR(30) CHECK(Length (TeamName) >= 10), PRIMARY KEY(TeamID) );

d) Show the structure of the table TEAM using a SQL statement.

Answer : DESC TEAM;

e) As per the preferences of the students four teams were formed as given below. Insert these four rows in TEAM table:

Row 1: (1, Team Titan)
Row 2: (2, Team Rockers)
Row 3: (3, Team Magnet)
Row 3: (4, Team Hurricane)

Answer : INSERT INTO TEAM VALUES (1, ‘Team Titan’);

INSERT INTO TEAM VALUES (2, ‘Team Rockers’);

INSERT INTO TEAM VALUES (1, ‘Team Magnet’);

INSERT INTO TEAM VALUES (1, ‘Team Hurricane’);

f) Show the contents of the table TEAM using a DML statement.

Answer : SELECT * FROM TEAM;

g) Now create another table MATCH_DETAILS and insert data as shown below. Choose appropriate data types and constraints for each attribute.

Table: MATCH_DETAILS

MatchIDMatchDateFirstTeamIDSecondTeamIDFirstTeamScoreSecondTeamScore
M12018-07-17129086
M22018-07-18344548
M32018-07-19137856
M42018-07-19245667
M52018-07-1814  3287
M62018-07-17236751

Table: MATCH_DETAILS

Answer : CREATE TABLE MATCH_DETAILS (

MatchId CHAR(2) NOT NULL PRIMARY KEY,

MatchDate DATE,

FirstTeamID INTEGER REFERENCES Team( TeamID),

SecondTeamID INTEGER REFERENCES Team(TeamID),

FirstTeamScore INTEGER,

SecondTeamScore INTEGER

);


5. Using the sports database containing two relations (TEAM, MATCH_DETAILS) and Write the queries for the following:

a) Display the MatchID of all those matches where both the teams have scored more than 70.

Answer : SELECT MatchID FROM MATCH_DETAILS WHERE FirstTeamScore > 70 AND SecondTeamScore > 70;

b) Display the MatchID of all those matches where FirstTeam has scored less than 70 but SecondTeam has scored more than 70.

Answer : SELECT MatchID FROM MATCH_DETAILS WHERE FirstTeamScore < 70 AND SecondTeamScore < 70;

c) Display the MatchID and date of matches played by Team 1 and won by it.

Answer : SELECT MatchID, MatchDate FROM MATCH_DETAILS WHERE (FirstTeamId = 1 AND FirstTeamScore > SecondTeamScore) OR (SecondTeamID = 1 AND SecondTeamScore > FirstTeamScore) ;

d) Display the MatchID of matches played by Team 2 and not won by it.

Answer : SELECT MatchID FROM MATCH_DETAILS WHERE SecondTeamScore < FirstTeamScore AND (FirstTeamID = 2 OR SecondTeamID = 2) ;

e) Change the name of the relation TEAM to T_DATA. Also change the attributes TeamID and TeamName to T_ID and T_NAME respectively.

Answer : ALTER TABLE TEAM RENAME TO T_DATA;

ALTER TABLE T_DATA CHANGE TeamID T_ID INTEGER;

ALTER TABLE T_DATA CHANGE TeamName T_Name VARCHAR(30) ;


6. A shop called Wonderful Garments who sells school uniforms maintains a database SCHOOLUNIFORM as shown below.

It consisted of two relations – UNIFORM and COST. They made UniformCode as the primary key for UNIFORM relations. Further, they used UniformCode and Size to be composite keys for COST relation. By analyzing the database schema and database state, specify SQL queries to rectify the following anomalies.

a) M/S Wonderful Garments also keeps handkerchiefs of red colour, medium size of Rs. 100 each.

b) INSERT INTO COST (UCode, Size, Price) values (7, ‘M’,100);

When the above query is used to insert data, the values for the handkerchief without entering its details in the UNIFORM relation is entered. Make a provision so that the data can be entered in the COST table only if it is already there in the UNIFORM table.

Answer : To overcome this anomalies, you need to create a foreign key constraint in cost table. Here UCode of cost table get related with the UniformCode Primary Key of Uniform table.

ALTER TABLE COST
ADD FOREIGN KEY (UCode) REFERENCES UNIFORM(UniformCode);

c) Further, they should be able to assign a new UCode to an item only if it has a valid UName. Write a query to add appropriate constraints to the SCHOOLUNIFORM database.

Answer : To overcome this this problem, you need to specify NOT NULL Constaint to UName column of UNIFORM table. So that you always suppose to enter valid name to uniform, while adding a record in a table.

ALTER TABLE UNIFORM
MODIFY UName VARCHAR(30) NOT NULL;

d) Add the constraint so that the price of an item is always greater than zero.

Answer : Add a CHECK constraint on price filed of COST table.

ALTER TABLE COST
ADD CONSTRAINT CHECK(Price > 0);



7. Consider the following table named “Product”, showing details of products being sold in a grocery shop.

Write SQL queries for the following:

a) Create the table Product with appropriate data types and constraints.

b) Identify the primary key in Product.

Answer: PCode

c) List the Product Code, Product name and price in descending order of their product name. If PName is the same then display the data in ascending order of price.

Answer:  SELECT PCODE, PNAME, UPRICE

             FROM PRODUCT

            ORDER BY PNAME DESC, UPRICE ASC;

d) Add a new column Discount to the table Product.

Answer:  ALTER TABLE PRODUCT ADD DISCOUNT DECIMAL (10,2);

e) Calculate the value of the discount in the table Product as 10 per cent of the UPrice for all those products where the UPrice is more than 100, otherwise the discount will be 0.

Answer:

mysql> UPDATE PRODUCT SET DISCOUNT = UPRICE * 0.10

            WHERE UPRICE > 100;

f) Increase the price by 12 per cent for all the products manufactured by Dove.

Answer:

mysql> UPDATE PRODUCT

            SET UPRICE = UPRICE + UPRICE * 0.12

          WHERE MANUFACTURER = ‘DOVE’;

g) Display the total number of products manufactured by each manufacturer.

Answer:

mysql > SELECT MANUFACTURER, COUNT(*)

          -> FROM PRODUCT

          -> GROUP BY MANUFACTURER;

Write the output(s) produced by executing the following queries on the basis of the information given above in the table Product:

h. SELECT PName, Avg(UPrice) FROM Product GROUP BY Pname;

i. SELECT DISTINCT Manufacturer FROM Product;

j. SELECT COUNT(DISTINCT PName) FROM Product;

k. SELECT PName, MAX(UPrice), MIN(UPrice) FROM Product GROUP BY PName;


a) Add a new column Discount in the INVENTORY table.

Answer: ALTER TABLE INVENTORY ADD DISCOUNT DECIMAL(10,2);

b) Set appropriate discount values for all cars keeping in mind the following:

(i) No discount is available on the LXI model.

(ii) VXI model gives a 10% discount.

(iii) A 12% discount is given on cars other than LXI model and VXI model.

Answer: (I)     UPDATE INVENTORY   SET DISCOUNT = NULL  WHERE MODEL = ‘LXI’;

(II)    UPDATE INVENTORY SET DISCOUNT = PRICE * 0.10 WHERE MODEL = ‘VXI’;

(II)    UPDATE INVENTORY SET DISCOUNT = PRICE * 0.12 WHERE MODEL NOT IN (‘LXI’, ‘VXI’)

c) Display the name of the costliest car with fuel type “Petrol”.

Answer: SELECT CARNAME FROM INVENTORY WHERE PRICE = (SELECT MAX(PRICE)    FROM INVENTORY WHERE FUELTYPE = ‘PETROL’ );

d) Calculate the average discount and total discount available on Car4.

Answer: SELECT AVG(DISCOUNT), SUM(DISCOUNT) FROM INVENTORY GROUP BY CARNAME HAVING CARNAME = ‘CAR4’;

e) List the total number of cars having no discount.

Answer:          SELECT * FROM INVENTORY

                    WHERE DISCOUNT IS NULL;

Read More

Chapter 5: Data Structures | NCERT Solution for class 12th COMPUTER SCIENCE

Chapter 5 – DATA Structures, , Class 12, Computer Science


In Computer Science, a data structure is a particular way of storing and organizing data in a computer so
that it can be used efficiently. Different kinds of data structures are suited to different kinds of
applications, and some are highly specialized to specific tasks. For example, Stacks are used in function
call during execution of a program, while B-trees are particularly well-suited for implementation of
databases. The data structure can be classified into following two types:
Simple Data Structure: These data structures are normally built from primitive data types like integers,
floats, characters. For example arrays and structure.
Compound Data Structure: simple data structures can be combined in various ways to form more
complex structure called compound structures. Linked Lists, Stack, Queues and Trees are examples of
compound data structure.
 

Data Structure Arrays
Data structure array is defined as linear sequence of finite number of objects of same type with following
set of operation:

  • Creating : defining an array of required size
  •  Insertion: addition of a new data element in the in the array
  •  Deletion: removal of a data element from the array
  •  Searching: searching for the specified data from the array
  •  Traversing: processing all the data elements of the array
  •  Sorting : arranging data elements of the array in increasing or decreasing order
  •  Merging : combining elements of two similar types of arrays to form a new array of same type

In C++ an array can be defined as
Datatype arrayname[size];
Where size defines the maximum number of elements can be hold in the array. For example
float b[10];//b is an array which can store maximum 10 float values
int c[5];
Array initialization
void main()
{i
nt b[10]={3,5,7,8,9};//
cout<<b[4]<<endl;
cout<<b[5]<<endl;
}
Output is
9
0
In the above example the statement int b[10]={3,5,7,8,9} assigns first 5 elements with the given values
and the rest elements are initialized with 0. Since in C++ index of an array starts from 0 to size-1 so the
expression b[4] denotes the 5th element of the array which is 9 and b[5] denotes 6th element which is
initialized with 0.

Chapter 5 - DATA Structures, Chapter Notes, Class 12, Computer Science

We can use two different search algorithms for searching a specific data from an array

  •  Linear search algorithm
  •  Binary search algorithm


Linear search algorithm
In Linear search, each element of the array is compared with the given item to be searched for. This
method continues until the searched item is found or the last item is compared.
#include<iostream.h>
int linear_search(int a[], int size, int item)
{
int i=0;
while(i<size&& a[i]!=item)
i++;
if(i<size)
return i;//returns the index number of the item in the array
else
return -1;//given item is not present in the array so it returns -1 since -1 is not a legal index number
}
void main()
{
int b[8]={2,4,5,7,8,9,12,15},size=8;
int item;
cout<<”enter a number to be searched for”;
cin>>item;
int p=linear_search(b, size, item); //search item in the array b
if(p==-1)
cout<<item<<” is not present in the array”<<endl;
else
cout<<item <<” is present in the array at index no “<<p;
}
In linear search algorithm, if the searched item is the first elements of the array then the loop terminates
after the first comparison (best case), if the searched item is the last element of the array then the loop
terminates after size time comparison (worst case) and if the searched item is middle element of the array
then the loop terminates after size/2 time comparisons (average case). For large size array linear search not an efficient algorithm but it can be used for unsorted array also.

Binary search algorithm
Binary search algorithm is applicable for already sorted array only. In this algorithm, to search for the
given item from the sorted array (in ascending order), the item is compared with the middle element of the
array. If the middle element is equal to the item then index of the middle element is returned, otherwise, if
item is less than the middle item then the item is present in first half segment of the array (i.e. between 0
to middle-1), so the next iteration will continue for first half only, if the item is larger than the middle
element then the item is present in second half of the array (i.e. between middle+1 to size-1), so the next
iteration will continue for second half segment of the array only. The same process continues until either
the item is found (search successful) or the segment is reduced to the single element and still the item is
not found (search unsuccessful).

#include<iostream.h>
int binary_search(int a[ ], int size, int item)
{
int first=0,last=size-1,middle;
while(first<=last)
{
middle=(first+last)/2;

if(item==a[middle])
return middle; // item is found
else if(item< a[middle])
last=middle-1; //item is present in left side of the middle element
else
first=middle+1; // item is present in right side of the middle element
}
return -1; //given item is not present in the array, here, -1 indicates unsuccessful search
}
void main()
{
int b[8]={2,4,5,7,8,9,12,15},size=8;
int item;
cout<<”enter a number to be searched for”;
cin>>item;
int p=binary_search(b, size, item); //search item in the array b
if(p==-1)
cout<<item<<” is not present in the array”<<endl;
else
cout<<item <<” is present in the array at index no “<<p;
}
Let us see how this algorithm work for item=12
Initializing first =0 ; last=size-1; where size=8
Iteration 1

Chapter 5 - DATA Structures, Chapter Notes, Class 12, Computer Science

First=0, last=7
middle=(first+last)/2=(0+7)/2=3 // note integer division 3.5 becomes 3
value of a[middle] i.e. a[3] is 7
7<12 then first= middle+1 i.e. 3 + 1 =4
iteration 2

Chapter 5 - DATA Structures, Chapter Notes, Class 12, Computer Science

first=4, last=7
middle=(first+last)/2=(4+7)/2=5
value of a[middle] i.e. a[5] is 9
9<12 then first=middle+1;5+1=6
iteration 3

Chapter 5 - DATA Structures, Chapter Notes, Class 12, Computer Science

first=6,last=7

middle=(first+last)/2 = (6+7)/2=6
value of a[middle] i.e. a[6] is 12 which is equal to the value of item being search i.e.12
As a successful search the function binary_search() will return to the main function with value 6 as
index of 12 in the given array. In main function p hold the return index number.

Note that each iteration of the algorithm divides the given array in to two equal segments and the only one
segment is compared for the search of the given item in the next iteration. For a given array of size N= 2n
elements, maximum n number of iterations are required to make sure whether the given item is present in
the given array or not, where as the linear requires maximum 2n number of iteration. For example, the
number of iteration required to search an item in the given array of 1000 elements, binary search requires
maximum 10 (as 1000210) iterations where as linear search requires maximum 1000 iterations.

Inserting a new element in an array
We can insert a new element in an array in two ways

  •  If the array is unordered, the new element is inserted at the end of the array
  •  If the array is sorted then the new element is added at appropriate position without altering the order. To achieve this, all elements greater than the new element are shifted. For example, to add 10 in the given array below:
Chapter 5 - DATA Structures, Chapter Notes, Class 12, Computer Science

Following program implement insertion operation for sorted array

#include<iostream.h>
void insert(int a[ ], int &n, int item) //n is the number of elements already present in the array
{
int i=n-1;
while (i>=0 && a[i]>item)
{
a[i+1]=a[i]; // shift the ith element one position towards right
i–;
}
a[i+1]=item; //insertion of item at appropriate place
n++; //after insertion, number of elements present in the array is increased by 1
}
void main()
{int a[10]={2,4,5,7,8,11,12,15},n=8;
int i=0;
cout<<“Original array is: ”;
for(i=0;i<n;i++)
cout<<a[i]<<”, “;
insert(a,n,10);
cout<<” Array after inserting 10 is: ”;

for(i=0; i<n; i++)
cout<<a[i]<<”, “;
}

Output is
 

Original array is:
2, 4, 5, 7, 8, 11, 12, 15
Array after inserting 10 is:
2, 4, 5, 7, 8, 10, 11, 12, 15

Deletion of an item from a sorted array
In this algorithm the item to be deleted from the sorted array is searched and if the item is found in the
array then the element is removed and the rest of the elements are shifted one position toward left in the
array to keep the ordered array undisturbed. Deletion operation reduces the number of elements present in
the array by1. For example, to remove 11 from the given array below:

Chapter 5 - DATA Structures, Chapter Notes, Class 12, Computer Science

Following program implement deletion operation for sorted array
#include<iostream.h>
void delete_item(int a[ ], int &n, int item) //n is the number of elements already present in the array
{int i=0;
while(i<n && a[i]<item)
i++;
if (a[i]==item) // given item is found
{while (i<n)
{a[i]=a[i+1]; // shift the (i+1)th element one position towards left
i++;
}
cout<<” Given item is successfully deleted”;
}
else
cout<<” Given item is not found in the array”;
n–;
}
void main()
{int a[10]={2,4,5,7,8,11,12,15},n=8;
int i=0;
cout<<“Original array is : ”;
for(i=0;i<n;i++)
cout<<a[i]<<”, “;
delete_item(a,n,11);
cout<<” Array after deleting 11 is: ”;
for(i=0; i<n; i++)
cout<<a[i]<<”, “;
}
Output is
Original array is:
2, 4, 5, 7, 8, 11, 12, 15
Given item is successfully deleted
Array after deleting 11 is:
2, 4, 5, 7, 8, 12, 15

Traversal
Processing of all elements (i.e. from first element to the last element) present in one-dimensional array is
called traversal. For example, printing all elements of an array, finding sum of all elements present in an
array.

#include<iostream.h>
void print_array(int a[ ], int n) //n is the number of elements present in the array
{int i;
cout<<” Given array is : ”;
for(i=0; i<n; i++)
cout<<a[i]<<”, “;
}
int sum(int a[ ], int n)
{int i,s=0;
for(i=0; i<n; i++)
s=s+a[i];
return s;
}
void main()
{int b[10]={3,5,6,2,8,4,1,12,25,13},n=10;
int i, s;
print_array(b,n);
s=sum(b,n);
cout<<” Sum of all elements of the given array is : ”<<s;
}

Output is
Given array is
3, 5, 6, 2, 8, 4, 1, 12, 25, 13
Sum of all elements of the given array is : 79

Sorting
The process of arranging the array elements in increasing (ascending) or decreasing (descending) order is known as sorting. There are several sorting techniques are available e.g. selection sort, insertion sort,
bubble sort, quick sort, heap short etc. But in CBSE syllabus only selection sort, insertion sort, bubble sort
are specified.
 

Selection Sort
The basic idea of a selection sort is to repeatedly select the smallest element in the remaining unsorted
array and exchange the selected smallest element with the first element of the unsorted array. For
example, consider the following unsorted array to be sorted using selection sort

Original array

Chapter 5 - DATA Structures, Chapter Notes, Class 12, Computer Science

iteration 1 : Select the smallest element from unsorted array which is 3 and exchange 3 with the first
element of the unsorted array i.e. exchange 3 with 8. After iteration 1 the element 3 is at its
final position in the array.

Chapter 5 - DATA Structures, Chapter Notes, Class 12, Computer Science

Iteration 2: The second pass identify 4 as the smallest element and then exchange 4 with 5

Chapter 5 - DATA Structures, Chapter Notes, Class 12, Computer Science

Iteration 3: The third pass identify 5 as the smallest element and then exchange 5 with 9

Chapter 5 - DATA Structures, Chapter Notes, Class 12, Computer Science

Iteration 4: The third pass identify 7 as the smallest element and then exchange 7 with 8

Chapter 5 - DATA Structures, Chapter Notes, Class 12, Computer Science

Iteration 5: The third pass identify 8 as the smallest element and then exchange 8 with 16

Chapter 5 - DATA Structures, Chapter Notes, Class 12, Computer Science

Iteration 6: The third pass identify 9 as the smallest element and then exchange 9 with 9 which makes
no effect.

The unsorted array with only one element i.e. 16 is already at its appropriate position so no more iteration
is required. Hence to sort n numbers, the number of iterations required is n-1, where in each next iteration,
the number of comparison required to find the smallest element is decreases by 1 as in each pass one
element is selected from the unsorted part of the array and moved at the end of sorted part of the array .
For n=7 the total number of comparison required is calculated as
Pass1: 6 comparisons i.e. (n-1)
Pass2: 5 comparisons i.e. (n-2)
Pass3: 4 comparisons i.e. (n-3)
Pass4: 3 comparisons i.e. (n-4)
Pass5: 2 comparisons i.e. (n-5)
Pass6: 1 comparison i.e. (n-6)=(n-(n-1))
Total comparison for n=(n-1)+(n-2)+(n-3)+ ……….+(n-(n-1))= n(n-1)/2
7=6+5+4+3+2+1=7*6/2=21;
Note: For given array of n elements, selection sort always executes n(n-1)/2 comparison statements
irrespective of whether the input array is already sorted(best case), partially sorted(average case) or
totally unsorted(i.e. in reverse order)(worst case).
#include<iostream.h>
void select_sort(int a[ ], int n) //n is the number of elements present in the array
{int i, j, p, small;
for(i=0;i<n-1;i++)
{small=a[i]; // initialize small with the first element of unsorted part of the array
p=i; // keep index of the smallest number of unsorted part of the array in p
66
for(j=i+1; j<n; j++) //loop for selecting the smallest element form unsorted array
{if(a[j]<small)
{small=a[j];
p=j;
}
}// end of inner loop———-
//———-exchange the smallest element with ith element————-
a[p]=a[i];
a[i]=small;
//———–end of exchange————-
}
}//end of function
void main( )
{int a[7]={8,5,9,3,16,4,7},n=7,i;
cout<<” Original array is : ”;
for(i=0;i<n;i++)
cout<<a[i]<<”, “;
select_sort(a,n);
cout<<” The sorted array is: ”;
for(i=0; i<n; i++)
cout<<a[i]<<”, “;
}
Output is
Original array is
8, 5, 9, 3, 16, 4, 7
The sorted array is
3, 4, 5, 7, 8, 9, 16

Insertion Sort
Insertion sort algorithm divides the array of n elements in to two subparts, the first subpart contain a[0] to
a[k] elements in sorted order and the second subpart contain a[k+1] to a[n] which are to be sorted. The
algorithm starts with only first element in the sorted subpart because array of one element is itself in
sorted order. In each pass, the first element of the unsorted subpart is removed and is inserted at the
appropriate position in the sorted array so that the sorted array remain in sorted order and hence in each
pass the size of the sorted subpart is increased by 1 and size of unsorted subpart is decreased by 1. This
process continues until all n-1 elements of the unsorted arrays are inserted at their appropriate position in
the sorted array.

For example, consider the following unsorted array to be sorted using selection sort
 

Study with National ToppersJoin the Super Achievers of Class 12Join Now

Original array
Chapter 5 - DATA Structures, Chapter Notes, Class 12, Computer Science
Sorted unsorted
Initially the sorted subpart contains only one element i.e. 8 and the unsorted subpart contains n-1 elements
where n is the number of elements in the given array.

Iteration1: To insert first element of the unsorted subpart i.e. 5 into the sorted subpart, 5 is compared
with all elements of the sorted subpart starting from rightmost element to the leftmost
element whose value is greater than 5, shift all elements of the sorted subpart whose value
is greater than 5 one position towards right to create an empty place at the appropriate position in the sorted array, store 5 at the created empty place, here 8 will move from position a[0] to a[1] and a[0] is filled by 5. After first pass the status of the array is:

Chapter 5 - DATA Structures, Chapter Notes, Class 12, Computer Science

Iteration2: In second pass 9 is the first element of the unsorted subpart, 9 is compared with 8, since 8
is less than 9 so no shifting takes place and the comparing loop terminates. So the element
9 is added at the rightmost end of the sorted subpart. After second pass the status of the
array is:

Chapter 5 - DATA Structures, Chapter Notes, Class 12, Computer Science

Iteration3: in third pass 3 is compared with 9, 8 and 5 and shift them one position towards right and
insert 3 at position a[0]. After third pass the status of the array is:

Chapter 5 - DATA Structures, Chapter Notes, Class 12, Computer Science

Iteration4: in forth pass 16 is greater than the largest number of the sorted subpart so it remains at the
same position in the array. After fourth pass the status of the array is:

Chapter 5 - DATA Structures, Chapter Notes, Class 12, Computer Science

Iteration5: in fifth pass 4 is inserted after 3. After third pass the status of the array is:

Chapter 5 - DATA Structures, Chapter Notes, Class 12, Computer Science

Iteration6: in sixth pass 7 is inserted after 5. After fifth pass the status of the array is:

Chapter 5 - DATA Structures, Chapter Notes, Class 12, Computer Science

Insertion sort take advantage of sorted(best case) or partially sorted(average case) array because if all
elements are at their right place then in each pass only one comparison is required to make sure that the
element is at its right position. So for n=7 only 6 (i.e. n-1) iterations are required and in each iteration only
one comparison is required i.e. total number of comparisons required= (n-1)=6 which is better than the
selection sort (for sorted array selection sort required n(n-1)/2 comparisons). Therefore insertion sort is
best suited for sorted or partially sorted arrays.
#include<iostream.h>
void insert_sort(int a[ ],int n) //n is the no of elements present in the array
{int i, j,p;
for (i=1; i<n; i++)
{p=a[i];
j=i-1;
//inner loop to shift all elements of sorted subpart one position towards right
0 1 2 3 4 5 6
3 5 8 9 16 4 7
68
while(j>=0&&a[j]>p)
{
a[j+1]=a[j];
j–;
}
//———end of inner loop
a[j+1]=p; //insert p in the sorted subpart
}
}
void main( )
{
int a[7]={8,5,9,3,16,4,7},n=7,i;
cout<<” Original array is : ”;
for(i=0;i<n;i++)
cout<<a[i]<<”, “;
insert_sort(a,n);
cout<<” The sorted array is: ”;
for(i=0; i<n; i++)
cout<<a[i]<<”, “;
}

Output is
Original array is
8, 5, 9, 3, 16, 4, 7
The sorted array is
3, 4, 5, 7, 8, 9, 16

Bubble Sort
Bubble sort compares a[i] with a[i+1] for all i=0..n-2, if a[i] and a[i+1] are not in ascending order then
exchange a[i] with a[i+1] immediately. After each iteration all elements which are not at their proper
position move at least one position towards their right place in the array. The process continues until all
elements get their proper place in the array (i.e. algorithm terminates if no exchange occurs in the last
iteration)
For example, consider the following unsorted array to be sorted using selection sort
Original array

Chapter 5 - DATA Structures, Chapter Notes, Class 12, Computer Science
Chapter 5 - DATA Structures, Chapter Notes, Class 12, Computer Science

Since in iteration1 some elements were exchanged with each other which shows that array
was not sorted yet, next iteration continues. The algorithm will terminate only if the last
iteration do not process any exchange operation which assure that all elements of the array
are in proper order.
Iteration2: only exchange operations are shown in each pass

Chapter 5 - DATA Structures, Chapter Notes, Class 12, Computer Science

In iteration 2 some exchange operations were processed, so, at least one more iteration is
required to assure that array is in sorted order.

Iteration3:

Chapter 5 - DATA Structures, Chapter Notes, Class 12, Computer Science

Iteration4:

Chapter 5 - DATA Structures, Chapter Notes, Class 12, Computer Science

Iteration5:

Chapter 5 - DATA Structures, Chapter Notes, Class 12, Computer Science

In iteration 5 no exchange operation executed because all elements are already in proper
order therefore the algorithm will terminate after 5th iteration.

Merging of two sorted arrays into third array in sorted order
Algorithm to merge arrays a[m](sorted in ascending order) and b[n](sorted in descending order) into third
array C[n+m] in ascending order.

#include<iostream.h>
Merge(int a[ ], int m, int b[n], int c[ ])// m is size of array a and n is the size of array b
{int i=0; // i points to the smallest element of the array a which is at index 0
int j=n-1;// j points to the smallest element of the array b which is at the index m-1 since b is
// sortet in descending order
int k=0; //k points to the first element of the array c
while(i<m&&j>=0)
{if(a[i]<b[j])
c[k++]=a[i++]; // copy from array a into array c and then increment i and k
else
c[k++]=b[j–]; // copy from array b into array c and then decrement j and increment k
}
while(i<m) //copy all remaining elements of array a
c[k++]=a[i++];
while(j>=0) //copy all remaining elements of array b
c[k++]=b[j–];
}
void main()
{int a[5]={2,4,5,6,7},m=5; //a is in ascending order
int b[6]={15,12,4,3,2,1},n=6; //b is in descending order
int c[11];
merge(a, m, b, n, c);
cout<<”The merged array is : ”;
for(int i=0; i<m+n; i++)
cout<<c[i]<”, “;
}
Output is
The merged array is:
1, 2, 2, 3, 4, 4, 5, 6, 7, 12, 15
 

Two dimensional arrays
In computing, row-major order and column-major order describe methods for storing multidimensional
arrays in linear memory. Following standard matrix notation, rows are identified by the first index of a
two-dimensional array and columns by the second index. Array layout is critical for correctly passing
arrays between programs written in different languages. Row-major order is used in C, C++; columnmajor
order is used in Fortran and MATLAB.

Row-major order
In row-major storage, a multidimensional array in linear memory is accessed such that rows are stored one
after the other. When using row-major order, the difference between addresses of array cells in increasing
rows is larger than addresses of cells in increasing columns. For example, consider this 2×3 array:

Chapter 5 - DATA Structures, Chapter Notes, Class 12, Computer Science
An array declared in C as
int A[2][3] = { {1, 2, 3}, {4, 5, 6} };
would be laid out contiguously in linear memory as:


1 2 3 4 5 6

To traverse this array in the order in which it is laid out in memory, one would use the following nested
loop:
for (i = 0; i < 2; i++)
for (j = 0; j < 3; j++)
cout<<A[i][j];
The difference in offset from one column to the next is 1*sizeof(type) and from one row to the next is
3*sizeof(type). The linear offset from the beginning of the array to any given element A[row][column]
can then be computed as:
offset = row*NUMCOLS + column
Address of element A[row][column] can be computed as:
Address of A[row][column]=base address of A + (row*NUMCOLS + column)* sizeof (type)
Where NUMCOLS is the number of columns in the array.
The above formula only works when using the C, C++ convention of labeling the first element 0. In other
words, row 1, column 2 in matrix A, would be represented as A[0][1]
Note that this technique generalizes, so a 2×2×2 array looks like:
int A[2][2][2] = {{{1,2}, {3,4}}, {{5,6}, {7,8}}};
and the array would be laid out in linear memory as:


1 2 3 4 5 6 7 8
 

Example 1.
For a given array A[10][20] is stored in the memory along the row with each of its elements occupying 4
bytes. Calculate address of A[3][5] if the base address of array A is 5000.
Solution:
For given array A[M][N] where M=Number of rows, N =Number of Columns present in the array
address of A[I][J]= base address+(I * N + J)*sizeof(type)
here M=10, N=20, I=3, J=5, sizeof(type)=4 bytes
address of A[3][5] = 5000 + (3 * 20 + 5) * 4
= 5000 + 65*4=5000+260=5260

Example 2.
An array A[50][20] is stored in the memory along the row with each of its elements occupying 8 bytes.
Find out the location of A[5][10], if A[4][5] is stored at 4000.
Solution:
Calculate base address of A i.e. address of A[0][0]
For given array A[M][N] where M=Number of rows, N =Number of Columns present in the array
address of A[I][J]= base address+(I * N + J)*sizeof(type)
here M=50, N=20, sizeof(type)=8, I=4, J=5
address of A[4][5] = base address + (4*20 +5)*8
4000 = base address + 85*8
Base address= 4000-85*8= 4000-680=3320
Now to find address of A[5][10]
here M=50, N=20, sizeof(type)=8, I=5, J=10
Address of A[5][10] = base address +(5*20 + 10)*8
=3320 + 110*8 = 3320+880 = 4200
As C, C++ supports n dimensional arrays along the row, the address calculation formula can be
generalized for n dimensional array as:
For 3 dimentional array A[m][n][p], find address of a[i][j][k]:
Address of a[i][j][k] = base address + ( (I * n + j ) * p + k ) * sizeof(type)
For 4 dimentional array A[m][n][p][q], find address of a[i][j][k][l]:
Address of a[i][j][k][l] = base address + ( ( (I * n + j ) * p + k ) * p + l ) * sizeof(type)
Column-major order is a similar method of flattening arrays onto linear memory, but the columns are
listed in sequence. The programming languages Fortran, MATLAB, use column-major ordering. The
array

Chapter 5 - DATA Structures, Chapter Notes, Class 12, Computer Science

if stored contiguously in linear memory with column-major order would look like the following:


1 4 2 5 3 6


The memory offset could then be computed as:
offset = row + column*NUMROWS
 

Address of element A[row][column] can be computed as:
 

Address of A[row][column]=base address of A + (column*NUMROWS +rows)* sizeof (type)

Where NUMROWS represents the number of rows in the array in this case, 2.
Treating a row-major array as a column-major array is the same as transposing it. Because performing a
transpose requires data movement, and is quite difficult to do in-place for non-square matrices, such
transpositions are rarely performed explicitly. For example, software libraries for linear algebra, such as
the BLAS, typically provide options to specify that certain matrices are to be interpreted in transposed
order to avoid the necessity of data movement

Example1.
For a given array A[10][20] is stored in the memory along the column with each of its elements occupying
4 bytes. Calculate address of A[3][5] if the base address of array A is 5000.
Solution:
For given array A[M][N] where M=Number of rows, N =Number of Columns present in the array
Address of A[I][J]= base address + (J * M + I)*sizeof(type)
here M=10, N=20, I=3, J=5, sizeof(type)=4 bytes
Address of A[3][5] = 5000 + (5 * 10 + 3) * 4
= 5000 + 53*4 = 5000+215 =5215

Example2.
An array A[50][20] is stored in the memory along the column with each of its elements occupying 8 bytes.
Find out the location of A[5][10], if A[4][5] is stored at 4000.
Solution:
Calculate base address of A i.e. address of A[0][0]
For given array A[M][N] where M=Number of rows, N =Number of Columns present in the array
address of A[I][J]= base address+(J * M + I)*sizeof(type)
here M=50, N=20, sizeof(type)=8, I=4, J=5
address of A[4][5] = base address + (5 * 50 +4)*8
4000 = base address + 254*8
Base address= 4000-55*8= 4000-2032=1968
Now to find address of A[5][10]
here M=50, N=20, sizeof(type)=8, I =5, J=10
Address of A[5][10] = base address +(10*50 + 10)*8
=1968 + 510*8 = 1968+4080 = 6048

Read More

Chapter 4: Pointers | NCERT Solution for class 12th COMPUTER SCIENCE

NCERT Solutions for Class 12 Computer Science (C++) – Pointers

Very Short Answer Type Questions    [1 mark each]

Question 1:
Write the definition of a function FixPay (float Pay[ ], int N) in C+ + , which should modify each element of the array Pay having N elements, as per the following rules :

Existing Salary ValueRequired Modification in Value
If less than 1,00,000Add 25% in the existing value
If >=1,00,000 and <20,000Add 20% in the existing value
If >=2,00,000Add 15% in the existing value

Аnswer:

Void FixPay(float Pay[],int N)
{
for(int i=0;i<N;i++)
{
if(Pay[i]<100000)
Pay[i]+= Pay[i]*0.25;
else if(Pay[i]<200000)
Pay[i]+= Pay[i]*0.20; 
else
Pay[i]+= Pay[i]*0.15 ;
 }
}

Question 2:
Write the definition of a member function INSERT() for a class QUEUE in C+ +, to remove a product from a dynamically allocated Queue of items considering the following code is already written as a part of the program.

Struct ITEM 
{
int INO; char INAME[20];
ITEM*Link;
};
class QUEUE 
{
ITEM *R,*F;
Public:
QUEUE(){R=NULL; F=NULL;}
void INSERT();
void DELETE();
~QUEUE();
};

Аnswer:

Void QUEUE::INSER()
{
ITEM*newitem = new ITEM; 
Cout<<"enter item number";
cin>>newitem → INO;
Cout<<"Enter item name";  
gets(newitem → INAME); 
newitem → Link = NULL; 
if (R==NULL)
R=F=newitem;
else
{
 R → Link=newitem; 
 R = newitem;
}

Short Answer Type Questions-I

Question 1:
Write the output from the following C+ + program code :

#include<iostream.h>
#include<ctype.h> 
void strcon(char s[])
{
for(int i=0,l=0;s[i]!='\0';i++,l++); 
fortint j=0;j<l;j++)
{
if(isupper(s[j]))
s[j]=tolower(s[j])+2; 
else if( islower(s[j])) 
s[j]=toupper(s[j])-2; 
else
s[j] ='@';
 }
}
void main()
{
char *c="Romeo Joliet"; 
strcon(c);
cout<<"Text="<<c<<endl; 
c=c+3;
cout<<"New Text="<<c<<endl; 
c=c+5-2 ;
cout<<"last Text= "<<c;
 }

Аnswer:
Text = tMKCM@lMJGCR
New Text = KCM@1MJGCR
Last Text = 1MJGCR

Question 2:
Obtain the output of the following C+ + program as expected to appear on the screen after its execution.
Important Note :
All the desired header files are already included in the code, which are required to run the code.

void main()
{
char *Text="AJANTA"; int *P, Num[]={l,5,7,9}
P=Num;
cout <<*p<< Text <<endl;
Text++;
P++;
cout<<*P<<Text<<endl;
}

Аnswer:
1AJANTA
5JANTA

Question 3:
Obtain the output from the following C+ + program as expected to appear on the screen after its execution.
Important Note :
• Adi the desired header files are already included in the code, which are required to run the code.

void main()
{
char *String="SARGAM"; 
int *Ptr, a[]={1,5,7,9}; 
ptr=a;
cout<<*ptr<<String<<endl;
String++; 
ptr+=3;
cout<<*ptr<<String<<endl;
}

Аnswer:
1 SARGAM
9ARGAM

Question 4:
Give the output of the following program segment: (Assuming all desired header file(s) are already included)

void main()
{
float *Ptr, Points[] = {20,50,30,40,10};
Ptr = points; 
cout<<*Ptr<<endl;
Ptr+=2;
Points[2]+=2.5; 
cout<<*Ptr<<endl;
Ptr++;
(*Ptr)+=2.5; 
cout<<Points[3]<<endl;
}

Аnswer:
20.00 32.5
42.50

Question 5:
Find the output of the following code :
Important Note :
All the header files are already included in the code, which are required to run the code.

void main()
{
char *String="SHAKTI";
int*Point,Value[]={10,15,70,19};
Point=Value;
cout<<*Point<<String<<endl;
String++;
Point++;
cout<<*Point<<String<<endl;
}

Аnswer:
10SHAKTI
15HAKTI

Question 6:
Write the output of the following C+ + program code :
Note : Assume all required header files are already being included in the program.

void change(int*s)
{
for(int i=0;i<4;i++)
{
if(*s<40)
{
if(*s%2==0)
*s=*s+10; 
else
*s=*s+ll; 
}
else
 {
if(*s%2==0)
*S=*S-10; 
else
*s=*s-ll;
}
cout<<*s<<" ";
s++;
}
}
void main()
{
int score[]={25,60,35,53 }; 
change(score);
}

Аnswer:
36 50 46 42

Short Answer Type Question-II

Question 1:
Find the output of the following program :

#include<iostream.h>
void in(int x,int y,int &z)
{
x+=y; 
y--;
z*=(x-y);
}
void out(int z,int y,int &x)
{
x*=y;
y++;
z/=(x+y);
}
void main()
{
int a=20, b=30, c=10;
out(a,c,b);
cout<<a<<"#"<<b<<"#"<<c<<"#"<<endl; 
in(b,c, a) ;
cout<<a<<"®"<<b<<"@"<<c<<"@"<<endl; 
out(a,b,c);
cout<<a<<"$"<<b<<"$"<<c<<"$"<<endl;
}

Аnswer:
20#300#10#
620@300@10@
620$300$3000$

Long Answer Type Questions

Question 1:
Find the output of the following code:

#include<iostream.h> 
void main()
{
int *Striker;
int Track[]={10,25,30,55}; 
Striker=Track; 
Track[1]+=30;
cout<<"Striker"<<*Striker<<endl; 
*Striker=-10;
Striker++;
cout<<"Next@"<<*Striker<<endl; 
Striker+=2;
cout<<"Last@"<<*Striker<<endl;
cout<<"Rest To"<<*Track[0]<<endl;
}

Аnswer:
Striker 10
Next@55
Last@55
Rest To 0

Question 2:
Find the output of the following code :

#include<iostream.h> 
void main()
{ 
int *Queen;
Moves[]={ll,22,33,44};
Queen=Moves;
Moves[2]+=22;
cout<<"Queen@"<<*Queen<<endl; 
*Queen-=ll;
Queen+=2;
cout<<”Now@"<<*Queen<<endl; 
Queen++;
cout<<"Finally@"<<*Queen<<endl;
cout<<"NewOrigin@"<<*Moves[0]<<endl; 
}

Аnswer:
Queen@11
Now@55
Finally@44
NewOrigin@0

Read More

Chapter 3: Data File Handling | NCERT Solution for class 12th COMPUTER SCIENCE

NCERT Solutions for Class 12 Computer Science (C++) – Data File Handling

TOPIC-1

Data File Handling :

Short Answer Type Questions-I[2 marks each]

Question 1.
Write a user defined function word_count() in C+ + to count how many words are present in a text file named “opinion.txt”. For Example, if the file opinion.txt contains following text:

Co-education system is necessary for a balanced society. With co-education system. Girls and Boys may develop a feeling of mutual respect towards each other.

The function should display the following :
Total number of words present in the text file are:24
Answer:

void word_count ()
 {
 ifstream i;char ch[20];int c=0;
 i.open("opinion.txt"); while(!i.eof())
 {
 i>>ch;
 C=C+1;
 }
 cout<<"Total number of words present in the text file are: "<<c;
 }

Question 2.
Write a function in C + + to count and display the no of three letter words in the file “VOWEL.TXT”.
Example :
If the file contains :
A boy is playing there. I love to eat pizza. A plane is in the sky.
Then the output should be : 4
Answer:

#include
 #include
 void wordcount()
 { char word[80];
 int cnt=0;
 ifstream fl;
 f1.open("VOWEL.TXT");
 while (fl>>word)
 {
 if (strlen(word) == 3)
 {
 cnt++;
 cout<<word<<endl;
 }
 }
 cout<<" number of three letter words = ”<<cnt;
 f1.close();
 }

Question 3.
Write a function AECount() in C++, which should read each character of a text file NOTES. TXT, should count and display the occurrence of alphabets A and E (including small cases a and e too).
Example :
If the file content is as follow :
CBSE enhanced its CCE guidelines further.
The AECount() function should display the output as
A:1
E:7
Answer:

Void AECount ()
 {
 Fstream obj;
 Obj.open ("NOTES.TXT", ios :: in) ;
 char x;
 int i=o, Sum A=0, Sum E=0,
 while (obj.get (ch)!=0)
 {
 obj . get (x) ;
 if (x=="A"||? x=="a")
 SumA =SumA+l;
 if(x=="E"|| x =="e")
 SumE=sumE+l;
 }
 cout<<"A:"<<sumA<<endl;
 Cout<<"E:"<< SumE;
 }

Question 4.
Write a function Countaroma() to count and display the number of times “Aroma” occurs in a text file “Cook.txt”.
Note : Only complete word “Aroma” should be counted. Words like “Aromatic” should not be counted.
Answer:

Void Countword ()
 {
 fstream tfile;
 clrscr();
 tfile.open ("Cook.txt", ios::in);
 char arr[80];
 char ch;
 int i=0;sum=0;n=0;
 while(tfile)
 {
 tfile.get (ch)
 arr[i] = ch;
 i++ ;
 if (strcpy(ch, "Aroma"))
 {
 i--;
 sum = sum+i;
 n++;
 }
 }
 Cout<<"Total number of Aroma:" <<n;
 }

Question 5.
Write a function EUCount ( ) in C++, which should read each character of a text file IMP TXT, should count and display the occurrence of alphabets E and U (including small cases e and u too).
Example:
If the file content is as follows ;
Updated information is simplified by official websites.
The EUCount() function should display the
output as
E:4
U:1
Answer:

void EUCount ()
 {
 fstream obj;
 obj. open("IMP.TXT");
 char ch;
 int i = 0 , sumE=0, sumU=0 ;
 while (obj. get (ch)! =0)
 {obj. get (ch);
 if(ch=="E"||ch=="e")
 SumE=sumE+l;
 if(ch=="U" ??ch =="u")
 SumU=SumU+l;
 } cout << "E : " «sum E<<endl;
 cout<<"U:"<<sumU<<endl;
 }

Question 6.
Write a function CountDig() in C++ which reads the content of a text file story.txt and displays the number of digits in it
For example if the file contains:
Amrapali was a queen of Gareware Kingdom in the year 1911. She had 2 daughters.
Her palace had 200 rooms.
Then the output on the screen should be :
Number of digits in Story: 8
Answer:

void CountDig ()
 {
 ifstream fin ("STORY.TXT");
 char ch;
 int count=0;
 while(!fin.eof ())
 {fin>>ch;
 if(isdigit(ch))
 count++;
 }
 cout<<"Number of digit in Story: "<<count;
 fin:close();
 }

Question 7.
Write a function in C + + to count the number of lines starting with a digit in a text file “Diary.Txt”.
Answer:

int countNum ()
 {
 ifstream fin("Diary.Txt");
 char ch[80];
 int count = 0;
 while (!fin.eof())
 {
 fin.getline (ch, 80);
 if (isdigit (ch[0])
 count ++;
 }
 fin.close( );
 return count;
 }

Question 8.
Write a function in C+ + to read the content of a text file “DELHI.TXT” and display all those lines on the screen, which are either starting with ‘D’ or starting with ‘M’.
Answer:

void disp ()
 {
 ifstream FILE("DELHI.TXT");
 int CA= 0;
 char LINE [80];
 while(FILE.getline(LINE,80))
 if(LINE [0]=='D' | | LINE[0]= 'M')
 puts(LINE);
 FILE.close();
 }

Question 9.
Write a function in C++ to read the content of a text file “PLACES.TXT” and display all those lines on screen, which are either starting with ‘P’ or starting with ‘S’.
Answer:

void disp ()
 {
 ifstream FILE("PLACES.TXT");
 int CA=0;
 char LINE [80];
 while(FILE.getline(LINE,80))
 if(LINE[0]=='P' | | LINE[0]=='S')
 puts(LINE);
 FILE.close();
 }

Question 10.
Write a function CountYouMe ( ) in C+ + which reads the contents of a text file story.txt and counts the words You and Me (not case sensitive).
For example, if the file contains:
You are my best friend.
You and me make a good team.
The function should display the output as:
Count for you : 2
Count for Me : 1
Answer:

void countyoume ( )
 {
 ifstream fil("story.txt");
 char word [80];
 int WC = 0, WM = 0;
 while (! fil.eof())
 {
 fil>>word;
 if ((strcmp WC++ ; (word, "You") = = 0)
 if (strcmp (word, "Me") = = 0) )
 WM++ ;
 }
 cout <<"count for you" << WC;
 cout <<"count for me" << WM;
 fil. close ( ) ;}

Question 11.
Write a function in C + + to count the number of lines present in a text file “STORY.TXT”.
Answer:

void CountLine ()
 {
 ifstream FIL("STORY.TXT");
 int LINES=0;
 char STR[80]; while {FIL.getline(STR, 80);
 LINES++;}
 cout<<"No. of Lines:"<<LINES;
 f.close();
 }

TOPIC-2

Data File Handling : binary file

Very Short Answer Type Questions[1 mark each]

Question 1.
Write the command to place the file pointer at the 10th and 4th record starting position using seekp() or seekg() command. File object is “file”? and record name is “STUDENT”.
Answer:
file.seekp( 9 * sizeof(STUDENT), ios::beg);
file.seekp( 3 * sizeof(STUDENT), ios::beg);

Question 2.
Find the output of the following C++ code considering that the binary file sp.dat already exists on the hard disk with 2 records in it.

class sports
 {
 int id;
 char sname[20];
 char coach[20];
 public:
 void entry();
 void show();
 void writing();
 void reading();
 }s;
 void sports::reading()
 {
 ifstream i;
 i.open("sp.dat");
 while(1)
 {
 i.read((char*)&s.size of (s));
 if(i.eof())
 break;
 else
 cout<<"\n"<<i.tellg();
 }
 i.close () ;
 }
 void main()
 {
 s.reading();
 }

Answer:
42
84

Question 3.
A binary file “games.dat” contains data of 10 games where each game’s data is an object of the following class :

class game
 {
 int gameno;
 char game_name[20];
 public :
 void enterdetails(){cin>>gameno;
 gets(game_name);}
 void enterdetails()
 {cout<<gameno<<endl<< game_name;}
 };
 With reference to this information, write C++ statement in the blank given below 
to move the file pointer to the end of file, ifstream ifile; game G;
 ifile.open("games.dat",ios::binary| ios::in);
 cout<<ifile.tellg();

Answer:

ifile.seekg(0,ios::end);

Question 4.
Fill in the blanks marked as Statement 1 and Statement 2, in the program segment given below with appropriate functions for the required task,

class Agency {
 int ANo; //Agent Code
 char AName [20]; //Agent Name
 char Mobile [12]; //Agent Mobile
 public:
 void Enter (); /*Function to
 enter details of agent*/
 void Disp (); /‘Function to
 display details of agent*/
 int RAno () {return ANo; }
 void UpdateMobile() /‘Function to update Mobile*/
 {
 cout<<"Updated Mobile:";
 gets(Mobile);
 };
 void AgentUpdate ()
 {
 fstream F;
 F. open ("AGENT.DAT", ios:: binary |ios:: in | ios:: out);
 int Updt=0;
 int UAno;
 cout<<"Ano (Agent No - to update Mobile):"; cin>> UAno;
 Agency A;
 while (!Updt && F.read ((char*) &A, sizeof (A)))
 {
 if (A. RAno ()==UAno)
 {
 //Statement 1: To call the function to Update Mobile No.
 //Statement 2: To reposition file pointer to re-write the updated object back in the file
F. Write ((char*)&A, sizeof (A));
Updt++;
 }
 }
 if (Updt)
 cout<<"Mobile Updated for Agent" <<UAno<<endl;
 else
 cout<< "Agent not in the Agency"<<endl;
 F. close ();
 }

Answer:
Statement 1:
A. Update Mobile ();
Statement 2:
F. seekg (-l*size of (A),ios:: (cur);

Question 5.
Fill in the blanks marked as Statement 1 and Statements 2, in the program segment given below with appropriate functions for the required task.

class Medical
 {
 int RNo; //Representative Code
 char Name [20];
 //Representative Name
 char Mobile [12];
 //Representative Mobile
 public :
 void Input (); // Function to enter all details
 void Show (); //Function to display all details
 int RRno () {return RNo;}
 void Change Mobile () //Function to change Mobile
 {
 cout<<"Changed Mobile:";
 gets (mobile);
 }
 };
 void RepUpdate ()
 {
 fstream F;
 F. open ("REP. DAT", ios : : binaryl ios:: in| ios:: out):
 int Change=0;
 int URno;
 cout<<"Rno (Rep No-to update Mobile) :"; cin>>URno;
 Medical M;
 while (! Change && F.read((char*) &M, sizeof (M))
 {
 if (M. RRno()==URno)
 {
 //Statement 1: To call the function to change Mobile No.
 //Statement 2: To reposition file pointer to re-write
 //the updated object back in the file ;
 F. write ((char*) &M, Sizeof (M)) ;
 Change++;
 }
 }
 if (change)
 cout <<"Mobile Changed for Rep" <<URno<<endl;
 else
 cout <<"Rep not in the Medical"< F. close ();
 }

Answer:
Statement 1:
M. Change Mobile ();
Statement 2:
F. seekp (-1* sizeof (M), ios :: (ur);

Question 6.
Fill in the blanks marked as Statement 1 and Statement 2, in the program segment given below with appropriate functions for the required task.

class Agent
 {
 long ACode; //Agent Code
 char AName [2 0] ; //Agent Name
 int Commission;
 public:
 void Enter (); //Function to enter details of Agent
 void Display (); //Function to display details of Agent
 void Update (int c) //Function to modify commission
 {
 Commission = C;
 }
 int GetComm(){return Commission;}
 long GetAcodeO {return Acode;}
 };
 void ChangeCommission (long AC, int CM)
 //AC " Agent Code, whose commission needs to change
 //CM " New Commission
 {
 fstream F;
 F. open ("AGENT.DAT", ios : :
 binary |ios : : in|ios : : out);
 char Changed='N';
 Agent A;
 while (Changed=='N'&& F. read ((char*) &A, size of (A)))
 { if (A. GetAcode ()==AC)
 {
 Changed = 'Y';
 A. Update (CM);
 //Statement 1: To place file pointer to the required position
------------------------;
 //Statement 2: To write the object A on to the binary file
 -------------------------;
 }
 }
 if (Changed=='N')
 cout <<"Agent not registered.";
 F. close ();

Answer:
Statement 1:
F. seekg (position);
Statement 2:
F. write ((char *) & A, size of (A));

Question 7.
Fill in the blanks marked as Statement 1 and Statement 2, in the program segment given below with appropriate functions for the required task.

class Customer {
 long int CNo; //Customer Number
 char CName[20]; //Customer Name
 char Email[30]; //Email of Customer
 public :
 void Allocate(); //Function to allocate a member
 void Show(); //Function to show customer data
 void ModifyEmail() //Function to modify Email ,
 { cout<<"Enter Modified Email:";
 gets(Email);
 }
 long int GetCno( ) {return CNo;}
 };
 void ChangeData( )
 {
 fstream File;
 File.open ("CUST.DAT", ios: :.binary | ios: :in|ios: :out);
 int Change=0, Location; long int ChangeCno;
 cout<<"Cno - whose email required to be modified:"; cin>>ChangeCno;
 Customer CU;
 while(Modify && File,read((char*)&CU, sizeof(CU)))
 {
 if (CU.GetCno()==ChangeCno)
 {
 CU.ModifyEmail ();
 Location=File.tellg()- sizeof(CU);
 //Statement 1: To place file pointer to the required position
 //Statement 2: To write the object CU on to the binary file
 Change ++;
 }
 }
 if (Change)
 cout<<"Email Modified... "<<endl;
 else
 cout <<"Customer not found... "<<endl;
 File. close();
 }

Answer:
Statement 1:
File.seekp (-l*size of (CU), ios ::cur);
Statement 2:
File.write ((char*)&CU, sizeof (CU));

Question 8.
A binary file “Students.dat” contains data of 10 students where each student’s data is an object of the following class:

class Student
 {
 int Rno; char Name [20] ;
 public:
 void EnterDataO {cin>>Rno; cin. getline (Name, 20)}
 void showData( ) {cout<<Rno<<”- <<Name<< endl;}
 };

With reference to this information, write output of the following program segment:

 ifstream file; Student S;
 File.open ("Students.dat", ios::binary |ios::in);
 File.seekg (0, ios::end);
 Cout<<File.tellg();

Answer:
A1
B2
C3

Question 9.
Observe the program segment given below carefully and answer the questions that follow:

class Stock
 {
 int Ino,Qty; char Item[20];
 public:
 void Enter( ){cin>>Ino;
 gets(Item); cin>>Qty;}
 void Issue (int Q) {Qty+=Q;}
 void Purchase (int Q) {Qty- =Q;)
 int GetlnoO {return Ino;}
 } ;
 void Purchaseltem (int Pino, int PQty)
 {
 fstream File;
 File.open ("STOCK.DAT", ios:: binary |ios: : in|ios : : out);
 Stock S;
 int Success=0;
 while (Success==0 && File . read ((char*) &S, sizeof (S)))
 {
 if (Pino==S. Getlno ())
 {
 S. Purchase (PQty);
 //Statement 1
 //Statement 2
 Success++ ;
 }
 }
 if (Success==l)
 cout<<" Purchase Updated" <<endl;
 else
 cout<<"Wrong Item No"<<endl;
 File . close ( ) ;
 }

(i)Write statement 1 to position the file pointer to the appropriate place, so that the data updation is done for the, required item.
(ii)Write statement 2 to perform the write operation so that the updation is done in the binary file.
Answer:
(i) file.seekp(-sizeof(Qty), ios::cur);
(ii) file.write((char*)&S, sizeof (stock));

Question 10.
Observe the program segment given below carefully and answer the questions that follow:

class Inventory
 { int Ano, Qty; char Article [20];
 public:
 void Input () (cin>>Ano; gets(Article); cin>>Qty;}
 void Issue (int Q) {Qty+=Q;}
 void Procure (int Q) {Qty-=Q;}
 int GetAno () {return Ano;}
 };
 void ProcureArticle (int TAno, int TQty)
 {
 fstream File;
 File.open("STOCK.DAT", ios :: binary|ios :: in|ios :: out);
 Inventory I;
 int Found=0;
 while (Found==0 && File, read((char*)&I. sizeof(I)))
 if (TAno=|S.GetAno())
 {
 I. Procure (TQty);
 //Statement 1
 //Statement 2
 Found++;
 }
 }
 if (Found==l)
 {
 cout<<" Procurement Updated" << endl ;
 else
 cout<<"Wrong Article No"<<endl; 
 File.close ( ) ;}

(i) Write statement 1 to position the file pointer to the appropriate place, so that the data updation is done for the required term.
(ii) Write statement 2 to perform the write operation so that the updation is done in the binary file.

Answer:
(i) file.seekp(sizeof (qty), ios :: cur);
(ii) file.write((char*)& |, sizeof(|));

Short Answer Type Questions-I[2 marks each]

Question 1.
Consider a file F containing objects E of class Emp. [Delhi, 2015]
(i) Write statement to position the file pointer to the end of the file.
(ii) Write statement to return the number of bytes from the begining of the file to the current position of the file pointer.
Answer:
(i) F. seekg (0,ios::end);
(ii) F.tellg();

Question 2.
Write a function RevText() to read a text file “Input.txt” and Print only word starting with ‘I’in reverse order. [Delhi, 2015]
Example : If value in text file is : INDIA IS MY COUNTRY v
Output will be : AIDNI SI MY COUNTRY
Answer:

void RevText ()
 {ifstream in ("Input.txt");
 char word[25];
 while(in)
 { in >>word;
 if (word[0] = = 'I' )
 cout<<strrev(word);
 else
 cout<<word;
 }

Question 3.
Write a function in C++ to search display details, where destination is “Chandigarh” from binary file “Flight.Dat”. Assuming the binary file is containing the objects of the following class :

 class FLIGHT
 { int Fno; // Flight Number
 char From [20]; // Flight Starting Point
 char To [20]; //Flight Destination
 public :
 char * GetFrom (); { return from;}
 char * GetTo(); { return To; }
 void input()
 {cin>>Fno>>; gets(From); get (To);}
 void show()
 {cout<<Fno<<":"<<From<<":"<<To<<endl; }
 };

Answer:

void Dispdetails ()
 {ifstream fin ("Flight.Dat");
 Flight F;
 while (fin)
 {fin.read((char*)&F,sizeof(F))
 if (strcmp(F.GetTo0, "Chandigarh"))
 F.show();
 }
 }

Question 4.
Write function definition for TOWER () in C++ to read content of a text file WRITEUE TXT. Count the presence of word TOWER and display the number of occurrences of this word.
Note:
— The word TOWER should be an independent word
— Ignore type cases (i.e. lower/upper case) Example:
If the content of the file WRITEUETXT is as follows:

Tower of hanoi is an interesting problem. Mobile phone tower is away from here. 
Views from EIFFEL TOWER are amazing.

The function TOWER() should display the following:
3
Answer:

void TOWER ()
{
int count = 0;
ifstream f (“WRITEUP.TXT”);
char s [20];
while (! f . eof () )
{
f >>S;
if (strcmpi (s, “TOWER”) = =0)
count ++;
}
cout<<count; f.close () ;
}

OR
Any other correct function defintion

Question 5.
Write a definition for function COSTLY() In C++ to read each record of a binary file GIFTS. DAT, find and display those items, which are priced more than 2000. Assume that the file GIFTS.DAT is created with the help of objects of class GIFTS, which is defined below:

class GIFTS
 {
 int CODE; char ITEM [20] ; float PRICE;
 public :
 void procure ()
 {
 cin>>CODE; gets (ITEM); cin>>PRICE;
 }
 void View ()
 {
 cout<<CODE<<":"<<ITEM<<":"< }
 float GetPrice () {return PRICE;
 }.

Answer:

void COSTLY ()
 {
 GIFTS G;
 ifstream fin ("GIFTS.DAT" , ios : : binary);
 while (fin.read( (char *)&G, sizeof (G)))
 {
 if (G.GetPrlce () >2000)
 G.View ();
 }
 fin. close ();

OR
Any other correct equivalent function definition

Question 6.
Find the output of the following C++ code considering that the binary file MEMBER. DAT exists on the hard disk with records of 100 members:

class MEMBER
 {
 int Mno; char Name [20];
 public :
 void In (); void out ();
 };
 void main ()
 {
 fstream MF;
 MF.open (:MEMBER.DAT", ios :: binary |ios :: in);
 MEMBER M;
 MF.read ((char*) &M, sizeof (M)) ;
 MF.read ((char*)) &M, sizeof (M));
 MF.read ((char*) &M, sizeof (M));
 int POSITION = MF. tellg () / sizeof (M) ;
 Cout<<"PRESENT REOCRD :"< MF.close () ;
 }

Answer:
PRESENT RECORD : 3

Question 7.
Write function definition for SUCCESS () in C + + to read the content of a text file STORY.TXT, count the presence of word STORY and display the number of occurrence of this word.
Note:
— The word STORY should be an independent word
— Ignore type cases (i.e. lower/upper case)
Example:
If the content of the file STORY.TXT is as follows

Success shows others that we can do it. It is possible to achieve success with hard work.
 Lot of money does not mean SUCCESS.

The function SUCCESS() should display the following:
3
Answer:

void SUCCESS ()
 {
 int count = 0 ;
 ifstream f ("STORY.TXT") ;
 char s [20] ;
 while (! f. eof () )
 {
 f >>S;
 if (strcmpi (s, "STORY") = = 0)
 //OR if (strcmpi (s, "SUCCESS")==0)
 count++;
 }
 cout<<count;
 f.close () ;

OR
Any other correct function definition

Question 8.
Write a definition for function Economic ( ) in C++ to read each record of a binary file ITEMS.DAT, find and display those items, which costs less than 2500. Assume that the file ITEMS. DAT is created with the help of objects of class ITEMS, which is defined below :

class ITEMS
 {
 int ID; char GIFT [20] ; float cost ;
 public :
 void Get ()
 {
 cin>>CODE,-gets (GIFT) ;
 cin>>cost;
 }
 void See ()
 {
 COUt < }
 float GetCost 0 {return Cost;}.
 } ;

Answer:

void Economic ()
 {
 ITEMS I;
 ifstream fin (" ITEMS.DAT",ios:: binary);
 while (fin.read ((char *)&I,sizeof (I)))
 {
 if (I.GetCost ()<2500)
 I. See ();
 }
 fin. close ();
 }

OR
Any other correct equivalent function definition

Question 9.
Find the output of the following C++ code considering that the binary file CLIENTS. DAT exists on the hard disk with records of 100 members.

class CLIENTS
 {
 int Cno; char Name [20];
 public :
 void In (); void out () ;
 } ;
 void main ( )
 {
 fstream CF;
 CF.open "CLIENTS.DAT", ios :: binary | ios :: in);
 CLIENTS C ;
 CF.read ((char*) &C, sizeof (C));
 CF.read ((char*) &C, sizeof (C));
 CF.read ((char*) &C, sizeof (C));
 int POS = CF. tellg ()/sizeof (C) ;
 cout < <"PRESENT RECORD :"< < POS < <endl;
 CF.close ();
 }

Answer:
PRESENT RECORD : 3

Question 10.
Write function definition for WORDABSTART () in C++ to read the content of a text file, JOY. TXT, and display all those words, which are starting with either ‘A’, ‘a’ or ‘B’, ‘b’.
Example:
If the content of the file JOY.TXT is as follows :
I love to eat apples and bananas. I was travelling to Ahmedabad to buy some clothes.
The function WORDABSTART() should display the following:
apples bananas Ahmedabad buy

Answer:

void WORDABSTART ()
 {
 ifstream fil; fi1.open ("JOY.TXT");
 char W[20];
 fi1> >W;
 while(!fil.eof())//OR While(fil)
 {
 if(strlen(w)==4) cout<<W<<" "; fi1> >W;
 }
 fil.close ();//Ignore
 }

Question 11.
Write a definition for function OFFER() in C+ + to read each object of a binary file OFFER.DAT, find and display details of those ITEMS, which has status as “ON OFFER”. Assume that the file OFFER.DAT is created with the help of objects of class ITEMS, which is defined below:

class ITEMS
 {
 int ID;char Item[20];Status[20]; float Price;
 public:
 void GetonstockO
 {
 cin>>ID;gets(Item);gets(Status);
 cin>>Price;
 }
 void view()
 {
 cout<<ID<<":"<<Item<<":"< }
 char*IStatus(){return Status}.
 };

Answer:

void OFFER ()
 {
 ITEMS;
 ifstream fin;
 fin.open("OFFER.DAT",ios::binary);
 while(fin.read(char*)&G size of(G))
 {
 if strcmp (G.Get status(),"ON OFFER")==0)
 G.view();
 }
 fin.close()///Ignore
}

Short Answer Type Questions-II[3 marks each]

Question 1.
Given the binary file CAR.Dat, containing . records of the following class CAR type:

class CAR
 {
 int C_No;
 char C_Name[20];
 float Mileage;
 public :
 void enter( )
 {
 cin>> C_No ; gets(C_Name) ; cin >>Mileage;
 }
 void display( )
 {
 cout<<C_No; cout<<C_Name;
 cout<<Mileage;
 }
 int RETURN_Mileage( )
 {
 return Mileage;
 }
 };

Write a function in C++, that would read contents from the file CAR.DAT and display the details of car with mileage between 100 to 150.
Answer:

void CARSearch ()
 {
 fstream FIL;
 FIL.open("CAR.DAT" , ios::binary|ios::in);
 CAR C;
 int Found = 0;
 while(FIL.read((char*)&C,sizeof(C)))
 {
 if ((C.RETURN_Mileage( )>100) &&
 (C.RETURN_Mileage( ) < 150) )
 {
 C.display();
 Found++;
 }
 }
 if (Found==0)
 cout<<"Sorry! No car found with mileage between 100 to 150";
 FIL.close () ;
 }

Question 2.
Given a binary file “SPORTS.DAT” containing records of the following class :

class Player
 { char PNO[10]; //player number
 char Name[20]; //Name of player
 int rank; //rank of the player
 public :
 void EnterData()
 {
 gets (PNO) ;gets (Name);cin>>rank;
 }
 void DisplayData()
 { cout<<setw(12)<<PNO;
 cout<<setw(32)<<Name;
 cout<<setw(3)<<rank<<endl;
 }
 int Ret_rank() {return rank;}
 } ;

Write a function in C++ that would read contents of the file “SPORTS.DAT” and display the
details of those jolayers whose rank is above 500.
Answer:

Void show()
 {
 fstream file;
 file.open( ("SPORTS. DAT"),ios::binary:ios::in));
 player P;
 while (file.read((char*)&P,sizeof(P)))
 if(P.rank>500)
 { Pi
 P.DisplayData () ;
 P.close();
 }
 }

Question 3.
Assuming the Class WORKER as declared below, write a function in C++ to read the objects of WORKER from binary file named WORKER. DAT and display those records of workers, whose Wage is less then 300.

class WORKER
 {
 int WNO;
 char WName [30] ; float Wage;
 public:
 void Enter() {cin>>WNo; gets (WName); cin>>wage;}
 void DISPO {Cout<<ENo<<'*'< float GetWage () {return Wage,-}
 };

Answer:

void Display()
 {
 ifstream fin;
 fin.open("WORKER.DAT",ios::in | ios:: binary) ;
 WORKER W;
 while (! fin. eof () )
 {
 fin.read((char*)&W,sizeof(W) ) ;
 if W. GetWage() <300)
 W. DISP ();
 }
 fin. close ();
 }

Question 4.
Assuming the class TOYS as declared below, write a function in C++ to read the objects of TOYS from binary file TOYS. DAT and display those details of those TOYS, which are meant for children of AgeRange “5 to 8”.

class TOYS 
{
 int ToyCode;
 char ToyName[10];
 char AgeRange;
 public:
 void Enter()
 {
 cin>>ToyCode;
 gets (ToyName);
 gets(AgeRange);
 }
 void Display()
 {
 cout<<ToyCode
 ToyName<<endl;
 cout<<AgeRange<<endl;
 }
 char*WhatAge() {returnAgeRange;}
 };

Answer:

void READTOYS()
 { fstream obj;
 obj.open ("TOYS.DAT",ios::binary);
 TOYS T;
 while (obj.read ((char*)&T, Sizeof(T)))
 if(T. WhatAge()>=5&&T.whatAge<=8)
 T. Display();
 obj. Close();
 }

Question 5.
Assuming the class GAMES as declared below, write a functions in C++ to read the objects of GAMES from binary file GAMES.DAT and display those details of those GAMES, which are meant for children of AgeRange “8 to 13”.

class GAMES
 {
 int GameCode; char GameName [10];
 char AgeRange;
 public:
 void Enter()
 {
 cin>>GameCode;
 gets(GameName);
 gets (AgeRange);
 }
 void Display()
 {
 cout<<GameCode<<":"GameName<<endl;
 cout<<AgeRange<<ehdl;
 }
 char* AgeR() {return AgeRange};
 };

Answer:

Void READGAMES ()
 { fstream obj ;obj. open ("GAMES.DAT",ios::binary);
 Games T;
 while (obj. read ((char*)&T,size of(T) ) )
 if (T. AgeR()>=8&& T. What Age <=13) T. Display ();
 obj. closet)
 }

Question 6.
Assuming the class ANTIQUE as declared below, write a function in C++ to read the objects of Antique from binary file ANTIQUE. DAT and display those antique items, which are priced between 10000 and 15000.

class ANTIQUE
 {
 int ANO;
 char Aname [10] ;
 float price;
 public :
 void BUY() {cin>>ANO;gets(Aname); cin>> price;}
 void SHOW ( )
 {
 cout<<ANO<<endl;
 cout < cout<<Price<<endl;
 }
 float Get Price ( ) {return Price;}
 };

Answer:

void Disp( )
 {
 ifstream fin;
 fin.open ("ANTIQUE.DAT", ios:: in |ios : : out | ios : : binary);
 Antique A;
 while (!fin.eof( ))
 { -
 fin.read ((char*) &A, sizeof(A));
 if (A.GetPrice ( )> 10000 & A.GetPrice( )<15000)
 A.SHOW( );
 }
 fin.close( ) ;
 }

Question 7.
Assuming the class VINTAGE as declared below, write a function in C++ to read the objects of VINTAGE from binary file VINTAGE.DAT and display those vintage vehicles, which are priced between 200000 and 250000.

class VINTAGE {
 int VNO; //Vehicle Number
 char VDesc[10]; //Vehicle Description
 float price;
 public:
 void GET( ) {cin>>VNO;gets(VDesc); cin>>Price;}
 void VIEW( )
 {
 cout<<VNO<<endl;
 cout<<VDesc<<endl;
 cout<<Price<<endl;
 }
 float ReturnPrice ( ) {return Price;}
 };

Answer:

void Disp( )
 {
 ifstream fin;
 fin.open ("VINTAGE.DAT", ios ::in| ios : : binary);
 vintage V; while (Ifin.eof())
 {
 fin.read ((char*)&V, sizeof(V));
 if (V.ReturnPrice( )> 200000 & &V.ReturnPrice( )<250000)
 V.VIEW ( );
 }
 fin.close ( );
 }

Question 8.
Write a function display () in C + + to display all the students who have got a distinction (scored percentage more than or equal to 75) from a binary file “stud.dat”, assuming the binary file is containing the objects of the following class:

class Student
 {
 int rno;
 char sname [20];
 int percent
 public;
 int retpercent()
 {
 return percent;
 }
 void getdetails()
 {
 cin>>rno;
 gets(sname);
 cin>>percent;
 }
 void showdetails()
 {
 cout<<rno;
 puts(sname);
 cout<<percent;
 }
 };

Answer:

void display()
 {
 student s;
 ifstream i("stud.dat");
 while(i.read(char*)&s,sizeof(s)))
 {
 if(s.retpercent()>=75)
 S.showdetails();
 }
 i.close();
 }

Question 9.
Write a function in C++ to search for the details (Phone no. and Calls) of those phones, which have more than 800 calls from a binary file “phones.dat”. Assuming that this binary file contains records/objects of class phone, which is defined below.

class Phone
 {
 char Phoneno[10]; int Calls;
 public:
 void Get() {gets (Phoneno); cin>>Calls;}
 void Billing!){cout<<Phoneno<<"#"< int GetCalls(){return Calls;}
 };

Answer:

void Search ()
 {
 ifstream infile;
 infile, open ("phones.dat");
 if(! infile)
 {
 cout<<"can't open the'file"; exit(); } while(! infile.eof()) } { infile, read (Char #) & P, 
size of (P); if (P. GetCalls()>800)
 P. Billing ();
 }
 infile.close ();
 }

Question 10.
Write a function in C++ to search for the details (Number and Calls) of those Mobile phones, which have more than 100 calls from a binary file “mobile.dat”. Assuming that this binary file contains records/objects of class Mobile, which is defined below:

class Mobile
 {
 char Number [10]; int Calls;
 public:
 void Enter () {gets (Number); cin>>Calls;}
 void Billing () {cout<<Number<<"#"< int GetCalls() {return Calls;}
 } ;

Answer:

void Search ( )
 {
 Mobile m;
 ifstream f;
 f.open ("mobile.dat");
 while (!f.eof())
 {
 f.read ((char*)&m, sizeof (m));
 if (m.GetCalls0>100)
 m.Billing ();
 }
 }

Question 11.
Write a function in C++ to search for a camera from a binary file “CAMERA.DAT” containing the objects of class CAMERA (as defined below). The user should enter the model no and the function should search and display the details of the camera,

class CAMERA {
 long ModelNo;
 float Megapixel; int Zoom;
 char Details[120];
 public:
 void Enter(){cin>>ModelNo>>Megapixel >> Zoom;
 gets (Details);}
 void Display( )
 {cout< <ModelNo< <MegaPixel<<Zoom< long GetModelNo(){return ModelNo;}
 };

Answer:

void cameraSearch ()
 {
 fstreamFIL;
 FIL.openCCAMERA.DAT", ios::binary|ios :: in );
 CAMERA B;
 long bn; int Found = 0;
 cout<<"Enter the Model Number"; cin >> bn;
 while (FIL.read((char*)&B, sizeof (B)))
 {
 if (FIL.GetModelNo() = = bn)
 {
 B.Display();
 Found ++;
 }}
 if(Found = = 0)
 cout<<"Sorry ! Camera not found"<<endl;
 FIL.close( );
 }

Long Answer Type Questions[4 marks each]

Question 1.
Write function definition for WORD4CHAR() in C++ to read the content of a text file FUN.TXT. and display all those words, which have four characters in it.
Example:
If the content of the file FUN.TXT is as follows :

When I was a small child, I used to play in the garden with my grand mom.
Those days were amazingly funful and I remember all the moments of that time.

The function WORD4CHAR() should display the following:

When used play with days were that time.

Answer:

Void WORD4CHAR ()
 {
 ifstream f("FUN.TXT");
 char ch[20] ;
 while (!f.eof())
 {
 f >>ch;
 if(strlen(ch)==4)
 cout<<ch,
 }
 f close(),
 }

Question 2.
Write a definition for function ONOFFER()in C++ to read each object of a binary file TOYS. DAT, find and display details of those toys, which have status as “ON OFFER”. Assume that the file Toys.DAT is created with the help of objects of class TOYS, which is defined below:

Class TOYS
 {
 int TID; char Toy[20], Status[20];
 float MRP;
 Public:
 void Getinstock()
 {
 cin>>TID;gets (Toy) ; gets (Status) ; cin»MRP:}
 void View()
 {
 Cout<<TID<<":"<<Toy<<":"<<MRP<< "":"<<Status<<endl;
 }
 Char *SeeOffer() {Return Status;}
 } ;

Answer:

Void ONOFFER ()
 {
 TOYS T;
 Ifstream fin;
 fin.open("TOYS.DAT", ios ::binary) ;
 while(fin.read((char*)&T,size (T) ))
 {
 if (strcmp(T.see offer(),"ON OFFER")= = 0)
 T.view();
 }
 fin.close();//Ignore
 }

Question 3.
Find the output of the following C++ code considering that the binary file CLIENT.DAT exists on the hard disk with a data of 1000 clients :

Class CLIENT
 {
 int Ccode;char CName[20];
 public:
 void Register();void Display();
 };
 void main()
 {
 fstream CFile;
 CFile.Open ( "CLIENT. DAT",ios::binary|ios::in); CLIENT C;
 CFile. read ( (char*) & C , sizeof(C)) ;
 cout<< "Rec: "<<CFile.tellg()/ sizeof(C)<<endl;
 CFile. read ( (char*) & C , sizeof*(C));
 CFile . read ( (char*) & C , sizeof(C));
 cout<<"Rec:"<<CFile.tellg()/ sizeof(C)<<endl;
 CFile.close () ;
 }

Answer:
Rec: 1
Rec: 3

Read More