Class 11-12

Class 11 Computer Science

BSEB 100-Day Study Plan
Notes, MCQs, and Solutions

Explore Class 11

Class 12 Computer Science

Advanced Topics & Practical Guide
Board Exam Preparation

Explore Class 12

Day 36: Introduction to C++ – Syntax, Data Types, and Basics | Class 11

Learn the fundamentals of C++ in Day 36 of Class 11 Computer Science. Covers syntax, data types, and basic program structure for beginners.

Day 36 – Chapter 5: Introduction to C++

Class 11 Computer Science

What is C++? (C++ क्या है?)

C++ is a high-level, object-oriented programming language developed by Bjarne Stroustrup in 1983. It is widely used for system software, application software, and game development.
C++ एक उच्च-स्तरीय, ऑब्जेक्ट-ओरिएंटेड प्रोग्रामिंग भाषा है जिसे 1983 में ब्जार्ने स्ट्रॉस्ट्रुप ने विकसित किया। यह सिस्टम सॉफ़्टवेयर, एप्लिकेशन सॉफ़्टवेयर और गेम डेवलपमेंट के लिए व्यापक रूप से उपयोग किया जाता है।

Why Learn C++? (C++ क्यों सीखें?)

  • Foundation for Other Languages (अन्य भाषाओं के लिए आधार): Learning C++ helps understand programming fundamentals that apply to other languages like Java and Python.
    C++ सीखने से प्रोग्रामिंग के मूल सिद्धांतों को समझने में मदद मिलती है जो अन्य भाषाओं जैसे जावा और पाइथन में लागू होते हैं।
  • Widely Used (व्यापक उपयोग): C++ is still used in competitive programming, embedded systems, and game development.
    C++ अभी भी प्रतिस्पर्धी प्रोग्रामिंग, एंबेडेड सिस्टम और गेम डेवलपमेंट में उपयोग किया जाता है।
  • Efficiency (कुशलता): C++ is faster and more efficient for performance-critical applications.
    C++ प्रदर्शन-महत्वपूर्ण अनुप्रयोगों के लिए तेज़ और अधिक कुशल है।

Features of C++ (C++ की विशेषताएं)

  • Object-Oriented Programming (ऑब्जेक्ट-ओरिएंटेड प्रोग्रामिंग): Focuses on objects and encapsulation, making code modular and reusable.
    ऑब्जेक्ट्स और इनकैप्सुलेशन पर ध्यान केंद्रित करता है, जिससे कोड मॉड्यूलर और पुन: उपयोग योग्य बनता है।
  • Extensibility (विस्तारशीलता): Developers can extend the language features as needed.
    डेवलपर्स आवश्यकता के अनुसार भाषा की सुविधाओं का विस्तार कर सकते हैं।
  • Portability (पोर्टेबिलिटी): C++ code can run on different platforms with minimal changes.
    C++ कोड न्यूनतम बदलाव के साथ विभिन्न प्लेटफॉर्म पर चल सकता है।
  • Rich Library (समृद्ध लाइब्रेरी): Provides a vast collection of built-in functions.
    अंतर्निर्मित कार्यों का एक बड़ा संग्रह प्रदान करता है।
  • High Performance (उच्च प्रदर्शन): Suitable for resource-intensive applications like games and simulations.
    संसाधन-गहन अनुप्रयोगों जैसे गेम्स और सिमुलेशन के लिए उपयुक्त।

Basic Syntax of C++ (C++ का बेसिक सिंटैक्स)

Every C++ program consists of the following components:
प्रत्येक C++ प्रोग्राम निम्नलिखित घटकों से बनता है:

  1. Header Files (हेडर फाइलें): Include libraries using #include. Example: #include <iostream>.
  2. Main Function (मुख्य फ़ंक्शन): The program execution starts from the main() function.
    प्रोग्राम का निष्पादन main() फ़ंक्शन से शुरू होता है।
  3. Statements (स्टेटमेंट): Instructions for the program, ending with a semicolon (;).
    प्रोग्राम के लिए निर्देश, जो सेमीकोलन (;) के साथ समाप्त होते हैं।

Example of a Simple C++ Program (सरल C++ प्रोग्राम का उदाहरण)

This program displays "Hello, World!" on the screen.
यह प्रोग्राम स्क्रीन पर "Hello, World!" दिखाता है:

#include 
using namespace std;

int main() {
    cout << "Hello, World!";
    return 0;
}

Data Types in C++ (C++ में डेटा प्रकार)

Data types define the type of data a variable can hold.
डेटा प्रकार यह परिभाषित करता है कि एक वेरिएबल किस प्रकार का डेटा रख सकता है।

  • int: Integer values (e.g., 1, 2, 100).
    पूर्णांक मान (जैसे, 1, 2, 100)।
  • float: Floating-point values (e.g., 3.14, 2.718).
    फ्लोटिंग-पॉइंट मान (जैसे, 3.14, 2.718)।
  • char: Single characters (e.g., 'A', 'B').
    एकल अक्षर (जैसे, 'A', 'B')।
  • string: Sequence of characters (e.g., "Hello").
    अक्षरों का अनुक्रम (जैसे, "Hello")।
  • bool: Boolean values (true or false).
    बूलियन मान (सत्य या असत्य)।

Advantages of C++ (C++ के लाभ)

  • Supports Both Procedural and Object-Oriented Programming (प्रोसीजरल और ऑब्जेक्ट-ओरिएंटेड प्रोग्रामिंग का समर्थन करता है): C++ allows developers to write code in both styles, giving flexibility in program design.
    C++ डेवलपर्स को दोनों शैली में कोड लिखने की अनुमति देता है, जिससे प्रोग्राम डिज़ाइन में लचीलापन मिलता है।
  • Provides Direct Control Over Hardware Resources (हार्डवेयर संसाधनों पर सीधा नियंत्रण प्रदान करता है): It offers low-level features to manage hardware directly.
    यह हार्डवेयर को सीधे प्रबंधित करने के लिए निम्न-स्तरीय सुविधाएँ प्रदान करता है।
  • High Performance (उच्च प्रदर्शन): C++ is faster compared to other high-level languages, making it suitable for resource-intensive applications.
    C++ अन्य उच्च-स्तरीय भाषाओं की तुलना में तेज़ है, जिससे यह संसाधन-गहन अनुप्रयोगों के लिए उपयुक्त है।
  • Rich Library Support (समृद्ध लाइब्रेरी समर्थन): It provides a wide range of built-in functions and libraries.
    यह अंतर्निर्मित कार्यों और लाइब्रेरी का एक व्यापक संग्रह प्रदान करता है।
  • Extensively Used in Real-Time Applications (वास्तविक समय अनुप्रयोगों में व्यापक उपयोग): C++ is used for developing operating systems, games, simulations, and embedded systems.
    C++ का उपयोग ऑपरेटिंग सिस्टम, गेम्स, सिमुलेशन और एंबेडेड सिस्टम्स के विकास के लिए किया जाता है।

Practice Questions (अभ्यास प्रश्न)

Multiple Choice Questions (MCQs)

  1. Who developed C++?
    (a) Dennis Ritchie | (b) James Gosling | (c) Bjarne Stroustrup | (d) Guido van Rossum
  2. Which of the following is a valid data type in C++?
    (a) int | (b) float | (c) char | (d) All of the above
  3. Which symbol is used to end a statement in C++?
    (a) : | (b) ; | (c) . | (d) ,
  4. What does #include do in C++?
    (a) Starts the main function | (b) Includes libraries | (c) Declares variables | (d) Ends the program
  5. What is the output of this code?
    
    #include <iostream>
    
    using namespace std;
    
    int main() {
    
        cout << "Welcome to C++!";
    
        return 0;
    
    }
    
            
    (a) Hello, World! | (b) Welcome to C++! | (c) Compilation Error | (d) None
  6. Which data type is used for decimal values in C++?
    (a) int | (b) float | (c) bool | (d) char
  7. What is the role of the main() function in C++?
    (a) It starts the program execution | (b) It includes libraries | (c) It declares variables | (d) None
  8. Which of these is a feature of C++?
    (a) Object-Oriented | (b) Procedural | (c) Both (a) and (b) | (d) None
  9. What will the following code output?
    
    #include <iostream>
    
    using namespace std;
    
    int main() {
    
        int a = 10;
    
        cout << a;
    
        return 0;
    
    }
    
            
    (a) 10 | (b) a | (c) Compilation Error | (d) None
  10. Which of the following is a valid C++ variable name?
    (a) 1name | (b) _name | (c) name@ | (d) None

Answers to MCQs:

1: (c), 2: (d), 3: (b), 4: (b), 5: (b), 6: (b), 7: (a), 8: (c), 9: (a), 10: (b)

Short Answer Questions (लघु उत्तरीय प्रश्न)

  1. What is C++?
    Answer: C++ is a high-level, object-oriented programming language developed by Bjarne Stroustrup.
    C++ एक उच्च-स्तरीय, ऑब्जेक्ट-ओरिएंटेड प्रोग्रामिंग भाषा है जिसे ब्जार्ने स्ट्रॉस्ट्रुप ने विकसित किया।
  2. List two features of C++.
    Answer: Object-Oriented Programming and High Performance.
    उत्तर: ऑब्जेक्ट-ओरिएंटेड प्रोग्रामिंग और उच्च प्रदर्शन।
  3. What is the purpose of the main() function in C++?
    Answer: It is the entry point of the program where execution begins.
    उत्तर: यह प्रोग्राम का प्रवेश बिंदु है जहाँ निष्पादन शुरू होता है।
  4. What are the basic data types in C++?
    Answer: int, float, char, string, bool.
    उत्तर: int, float, char, string, bool।
  5. Write a simple C++ program to display your name.
    Answer:
    
    #include <iostream>
    
    using namespace std;
    
    int main() {
    
        cout << "My name is [Your Name]";
    
        return 0;
    
    }
    
    
    उत्तर:
    
    #include <iostream>
    
    using namespace std;
    
    int main() {
    
        cout << "मेरा नाम [आपका नाम] है";
    
        return 0;
    
    }
    
    

Long Answer Questions (दीर्घ उत्तरीय प्रश्न)

  1. Explain the basic syntax of a C++ program with an example.
  2. Discuss the features of C++ and how it differs from other programming languages.
  3. What are the different data types in C++? Provide examples of each.

Post a Comment