Instruction about “Arrays within a Class”.

Before you know about the “Arrays within a Class”, we will help to identify the necessary information of object oriented programming language. It is a useful definition in this program language before you can explore the classes and objects that Arrays within a Class belong to. If you have been waiting for our instruction, we will suggest the message you need in this article. Click the below for explanations right here! 

What is “Arrays within a Class”?

We will start with the C++. What is C++ and their function?. Firstly, C++ is not only an object oriented programming language, but is an extension of C language also. C++ is considered an intermediate level language as it comprises a confirmation of both high and low level language features. Moreover, it is an object oriented programming language but C++ is not purely object oriented. C++ Functions include syntax, return type, function name, parameters, and function body.  

Arrays are one of the objects in the oriented programming language and can be announced as the class’s member. Moreover, it is asserted as public or asserted or protected by the class’s members.

If you are confused the content of the arrays, please find the below example to understand the definition about arrays by class’s member:

#include<iostream>

const int size=5;

class student

{

int roll_no;
int marks[size];
public:
void getdata ();
void tot_marks ();
} ;

void student :: getdata ()
{
cout<<"\nEnter roll no: ";
Cin>>roll_no;
for(int i=0; i<size; i++)
{
cout<<"Enter marks in subject"<<(i+1)<<": ";
cin>>marks[i] ;
}

void student :: tot_marks() //calculating total marks
{
int total=0;
for(int i=0; i<size; i++)
total+ = marks[i];
cout<<"\n\nTotal marks "<<total;
}

void main()
student stu;
stu.getdata() ;
stu.tot_marks() ;
getch();
}

The output as follow:

Output:

Enter roll no: 101
Enter marks in subject 1: 67
Enter marks in subject 2 : 54
Enter marks in subject 3 : 68
Enter marks in subject 4 : 72
Enter marks in subject 5 : 82
Total marks = 343

Conclusion 

We hope this post shares with you the useful information of “Arrays within a Class” for your lesson. We have provided significant knowledge of C++, the function and classes and objectives as well, it helps you to know the background of object oriented programming. With this definition, you are able to learn more about the function and problem when you study this objective. Please let me know if you need further information. Have a good day ahead! 

Scroll to Top