Posts

C++ Program to Load and Display Records of N Products Using Class (Inline Function)

In C++, a class can be used to store the details of multiple products. An array of objects allows us to create and manage records of N products. An inline member function can perform small operations, such as calculating profit or loss. C++ में Class का उपयोग करके अनेक Products का रिकॉर्ड स्टोर किया जा सकता है। Array of Objects की सहायता से हम N Products के रिकॉर्ड को इनपुट और प्रदर्शित कर सकते हैं। Inline Member Function का उपयोग Profit या Loss जैसी छोटी गणनाओं के लिए किया जा सकता है। C++ Program #include <iostream> #include <string> using namespace std; #define N 5 class Product { int pid; string pname; float costprice; float sellprice; // Inline member function void profitloss() { float pl = sellprice - costprice; if (pl > 0) { cout << "Profit = " << pl << endl; } else if (pl < 0) { cout << "Loss = " << -pl << e...

C++ Program to Load and Store Records of N Employees N कर्मचारियों के रिकॉर्ड को इनपुट एवं स्टोर करने का C++ प्रोग्राम

In C++, an array of objects can be used to store records of multiple employees. Each object represents one employee and stores information such as Employee ID, Name, and Basic Salary. We can also calculate different salary components such as Travel Allowance (TA), Dearness Allowance (DA), House Rent Allowance (HRA), and Gross Salary using member functions. C++ में Multiple Employees के Records को Store करने के लिए Array of Objects का उपयोग किया जा सकता है। प्रत्येक Object एक Employee को दर्शाता है तथा इसमें Employee ID, Name और Basic Salary जैसी जानकारियाँ Store की जाती हैं। Member Functions की सहायता से Travel Allowance (TA), Dearness Allowance (DA), House Rent Allowance (HRA) तथा Gross Salary की गणना भी की जा सकती है। Salary Calculation Formula (सैलरी कैलकुलेशन फॉर्मूला) TA = 25% of Basic Salary DA = 50% of Basic Salary HRA = 10% of Basic Salary Gross Salary = Basic Salary + TA + DA + HRA Program: #include <iostream> #include <string> #include <iomanip> using namesp...

C++ Program to Load and Store Records of N Students N विद्यार्थियों के रिकॉर्ड को इनपुट एवं स्टोर करने का C++ प्रोग्राम

In C++, an array of objects can be used to store records of multiple students. Each object represents one student and contains information such as Roll Number, Name, and Marks. By creating an array of objects, we can accept and display the records of multiple students using loops. C++ में Multiple Students के Records को Store करने के लिए Array of Objects का उपयोग किया जा सकता है। प्रत्येक Object एक Student को दर्शाता है तथा इसमें Roll Number, Name और Marks जैसी जानकारियाँ Store की जाती हैं। Objects का Array बनाकर Loops की सहायता से अनेक विद्यार्थियों के Records को Input तथा Display किया जा सकता है। Program: #include <iostream> #include <string> using namespace std; #define N 5 class Student { int rollno; string name; float marks; static int count; public: Student() { count++; } void setStudent(); void getStudent(); }; // Initializing static data member int Student::count = 0; // Function to accept student details void Student::set...

Basic Program Structure of C++ (C++ प्रोग्राम का स्ट्रक्चर)

Every C++ program consists of different sections that perform specific tasks. These sections may be written in a single source file or organized into multiple files for better program organization and reusability. A general structure of a C++ program is shown below: प्रत्येक C++ प्रोग्राम में अलग-अलग भाग होते हैं, जो विशेष कार्य करते हैं। इन भागों को एक ही Source File में लिखा जा सकता है या प्रोग्राम को बेहतर तरीके से व्यवस्थित करने तथा दोबारा उपयोग करने के लिए अलग-अलग Files में रखा जा सकता है। C++ प्रोग्राम का सामान्य प्रारूप निम्नलिखित है: General Structure of a C++ Program ------------------------------------------------ 1. Include Files (Header Files) 2. Global Declarations - Global Variables - Constants - Function Prototypes 3. Class Declaration - Data Members - Member Function Declarations 4. Member Function Definitions - Definitions of Class Member Functions 5. Main Function - Variable Declarations - Executable Statements - Function Calls 6. Other Func...

Scope Resolution Operator or Scope Access Operator (::) in C++ C++ में स्कोप रेजोल्यूशन ऑपरेटर या स्कोप एक्सेस ऑपरेटर (::)

C++ programs are generally organized into different scopes, such as global scope, local scope, class scope, and namespace scope. Sometimes, two variables may have the same name but belong to different scopes. The Scope Resolution Operator ( :: ) is used to specify the scope to which a particular identifier belongs. It helps access global variables, define class member functions outside the class, and access static class members. C++ प्रोग्राम में अलग-अलग Scope होते हैं, जैसे Global Scope, Local Scope, Class Scope तथा Namespace Scope। कभी-कभी दो Variables के नाम समान हो सकते हैं, लेकिन वे अलग-अलग Scopes से संबंधित होते हैं। Scope Resolution Operator ( :: ) का उपयोग यह निर्धारित करने के लिए किया जाता है कि कोई Identifier किस Scope से संबंधित है। इसकी सहायता से Global Variables को Access किया जा सकता है, Class के बाहर Member Functions को Define किया जा सकता है तथा Class के Static Members को Access किया जा सकता है। 1. Accessing Global Variables (ग्लोबल वेरिएबल को एक्सेस करना) If a global v...

Block, Block Statement and Compound Statement in C++ C++ में ब्लॉक, ब्लॉक स्टेटमेंट एवं कंपाउंड स्टेटमेंट Block (ब्लॉक)

A block is a compound statement that consists of zero or more statements enclosed within curly braces { } . A block is treated as a single statement wherever a statement is expected in a program. ब्लॉक एक कंपाउंड स्टेटमेंट होता है, जिसमें शून्य या उससे अधिक Statements का समूह Curly Braces { } के अंदर लिखा जाता है। प्रोग्राम में जहाँ भी एक Statement की आवश्यकता होती है, वहाँ Block का उपयोग एक Single Statement के रूप में किया जा सकता है। A block begins with an opening curly brace { and ends with a closing curly brace } . किसी Block का प्रारंभ Opening Curly Brace { से तथा अंत Closing Curly Brace } से होता है। Syntax: { statement1; statement2; statement3; } Block Statement and Compound Statement In C++, the terms block , block statement , and compound statement are commonly used to describe a group of statements enclosed within curly braces { } . C++ में Block, Block Statement और Compound Statement शब्दों का उपयोग सामान्यतः Curly Braces { } के अंदर लिखे गए Statements के स...

Reference (रेफरेंस) in C++, Syntax of Reference (रेफरेंस का सिंटैक्स)

A reference is an alternative name or alias for an existing variable or object. It allows us to access the same variable using two different names. For example, Amitabh Bachchan is also known as Big B. Both names refer to the same person. Similarly, in C++, a reference provides an alternative name for an existing variable. A reference does not create a separate variable or a copy of the original variable. Both the original variable and its reference refer to the same memory location. Therefore, any change made through the reference also affects the original variable. एक Reference किसी पहले से मौजूद Variable या Object का वैकल्पिक नाम (Alias) होता है। इसकी सहायता से हम एक ही Variable को दो अलग-अलग नामों से Access कर सकते हैं। उदाहरण के लिए, अमिताभ बच्चन को बिग बी के नाम से भी जाना जाता है। ये दोनों नाम एक ही व्यक्ति को दर्शाते हैं। इसी प्रकार C++ में Reference किसी पहले से मौजूद Variable को एक दूसरा नाम प्रदान करता है। Reference किसी अलग Variable या Original Variable की Copy को Create नह...