Ask Programiz - Human Support for Coding Beginners

Explore questions from fellow beginners answered by our human experts. Have some doubts about coding fundamentals? Enroll in our course and get personalized help right within your lessons.

  • All
  • Python
  • C
  • Java
  • CPP
  • SQL
  • JS
  • HTML
  • CSS
Kelish Rai
Expert
last year
Kelish Rai answered

By keeping variables private and using public getter and setter methods, we can control how the data is accessed or modified. This provides better security, flexibility, and maintainability in your code.

For example, you might want to add validation or extra logic inside a setter to ensure the value is correct before it's saved:

class Person {
    private:
        int age;

    public:
        int getAge() {
            return age;
        }

        void setAge(int newAge) {
            // Validation inside setter
            if (newAge > 0) {
                age = newAge;
            }
        }
};

int main() {
    Person p;
    p.setAge(25);    // Setting age via setter
    cout << p.getAge();    // Getting age via getter
}

Here, we ensure that age can never be set to a negative value.

If we had made age public, anyone could do something like p.age = -5;, which would break the logic of the program.

Simply put,

  • Private variables protect the integrity of the data.

  • Getters and setters allow you to add rules (like validation) easily without changing how other parts of your code use the class.

  • It also follows the principle of encapsulation — one of the four main principles of object-oriented programming (OOP).

C++
This question was asked as part of the Learn C++ OOP course.
Kelish Rai
Expert
last year
Kelish Rai answered

Here's how you can print the result of (5 * (9 + 13) / 2) * 7 on the screen in C++, with the output ending on a new line:

#include <iostream>
using namespace std;

int main() {
    cout << (5 * (9 + 13) / 2) * 7 << endl;
    return 0;
}

If this isn't what you were looking for, let me know—I'm happy to help.

Also, if you're just getting started, I’d recommend going through the course step by step. That way, you'll build a strong foundation in C++ and understand concepts more easily.

Just a quick note: We focus on answering questions related to the page or course.

C++
This question was asked as part of the Learn C++ Basics course.
A
last year
Abhinavcountry asked
Kelish Rai
Expert
last year
Kelish Rai answered

The double data type is used to store numbers with decimal parts, like 19.5, 7.7, and -10.45. It's very similar to float, but it can hold larger values with more precision.

Since we've already covered this in the Numbers and Text lesson, feel free to go back and have a quick recap.

If you have more questions, just drop them below. I'm happy to help.

C++
This question was asked as part of the Learn C++ Basics course.
Ethan Clausing
last year
Ethancountry asked
Abhilekh Gautam
Expert
last year

Great question!

Just like we use languages such as English or Spanish to communicate with each other, C++ is a language used to communicate with computers. These types of languages are called programming languages because they allow us to write instructions that a computer can understand and execute.

So, in simple terms, C++ is a programming language used to create software, applications, and systems by giving precise instructions to computers.

If you have more questions, feel free to ask—I’m here to help!

C++
This question was asked as part of the Learn C++ Basics course.
Nguyễn Tấn Phát
PRO
last year
Nguyễncountry asked
Abhilekh Gautam
Expert
last year

You can create a 3D array in C++ like this:

int arr[2][3][4] = {
    {
        {1, 2, 3, 4},
        {5, 6, 7, 8},
        {9, 10, 11, 12}
    },
    {
        {13, 14, 15, 16},
        {17, 18, 19, 20},
        {21, 22, 23, 24}
    }
};

Here, arr is a 3D array with dimensions 2 × 3 × 4:

  • It has 2 layers (or "pages")

  • Each layer contains 3 rows

  • Each row has 4 columns

Accessing Elements:

You can access or modify individual elements like this:

arr[1][2][3] = 99; // Sets the value in the second layer, third row, fourth column to 99

Use Case Tip:

3D arrays are useful for representing data like a stack of 2D grids—common in simulations, image processing, or games.

C++
This question was asked as part of the Learn C++ Basics course.
H
last year
H9910523@gmail.comcountry asked
Kelish Rai
Expert
last year
Kelish Rai answered

It looks like you're a bit confused about the difference between printing 67 (a number) and "67" (a string). No worries—let me break it down for you with a simple example.

When printing "67" (a string), you need to enclose it in quotation marks:

cout << "67";

But when printing 67 (a number), you don’t need quotation marks:

cout << 67;

Hope this helps! If you need more clarification, feel free to ask a follow-up question below—I'm happy to help.

C++
This question was asked as part of the Learn C++ Basics course.