Using Array Inside Class | C ++ Tutorial | Mr. Kishore

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hi welcome to variety this is sure and today we are going to discuss about how to use the eros inside the class we know that class is the combination of data members and member functions and at the same time class allows to declare both the primitive and derived arrive at one place class is the combination of both primitive and derived data type now in decision I am going to cover how to declare the array inside the class actually we know that array is a derived data that means I want to explain how to use the derived data type array inside the class okay first of all what is an array array is nothing but collection of homogeneous variables when individual variables for example for example one student is having six subject marks generally we have to declare six variables for that later we have to input six values and later we have to input C in means we have to use six variables and we have to go for C in also for six times or we have to separate with the extraction operator six times now it is getting lengthy and we have to remember all the variable names to avoid this problem the only simple solution is correct because of array LoZ to define several variables of same type under one name that means instead of declaring six subjects now I am going to define one array type variable okay when it is a de type variable it is able to store all the six values at one place under one name under we have to use the seen also in a loop let's say program length also produced and here we have to remember only one variable name that's why program performance also increase now I am going to explain how to use array inside the class and here I was streamed or h4 standard input/output operations next hash include' corner door Shh first CLRS here and get CH functions next now this header file is for standard input/output operations means Co can't see and Coney or H is first CLR scrn get CH functions now I am going to start a class class student I am going to take the plus student and the data members are int ID student name and subject mark and here I want to store 6 subjects then generally we have to declare 6 variables instead of that I am going to declare array subject of 6 now here we can store the student ID here name and here 6 subject marks ok next I want to enter the data for this members that is why would get student one function and wide result one function okay here I am going to use two functions number functions one is get student for input process and to show the result why it is result next now I am going to close the class now the class declaration completed and I have to define the member functions now I want to define the member functions outside of the class when we are defining a member function outside of the class we have to start with class name and scope operator that's were here I am going to store a definition void first a written type next get student is the number function of student class that is what student class name and scope operator later function name get student here I want to input the data next C out enter student ID commonly next C in ID under now by using this one we are entering the ID value under name now two values are stored later we have to store the subject wise marks we have to find out the subject means we have to input the subject wise marks and here how many subjects are there six subjects are there that is why here I am going to run it like this see out enter six subject marks and here when it is six subject marks it is better to go for a loop that's why I am going to start a for loop for int I equal to zero in C++ we are having this facility we can declare the variables at any place that is why I am going to declare a local variable inside the for loop next I'll f96 why because six subjects we are having next I plus plus now this loop is going to repeat 6 times from 0 to 5 later C in C in subject of I now saw now what happened seen is going to read the value for subject of I I value started with 0 subject of 0 later subject of one two three four five now six values are going to be stored now the loop closed and function also closed when the function is called what happens first of all it is reading the student ID latest trending later it is really six subject marks now all the subject remarks are going to be stored now I want to find out the student result I want to find out the student result that is why what I am doing here see this void and this one also number of student class now thus while student : : and function name is what result now result okay here I want to find our first of all student total i NT total local variable equal to I want to find out what six subjects addition now I have to use six subjects now six of these are declared as Irena that is why here I am going to write once again see this int total float average now totally the initial easy to get to zero means local variables one is total one is our later I want to find out the total that is why once again first int I equal to 0 I less then six I plus Chris and Here I am going to find out total total plus C equal to a subject of I now subject of actual meaning is what now total equal to total place subject of i okay now what happened total total starting value 0 0 plus subject of I value 0 subject of 0 means first subject for example it is not just is you it is the name and here subject 0 1 2 3 4 5 now it is having some values like this okay now here some IDs to means ID number 1 ROM or nama now suppose it is the object which object okay test object for example we are going to declare it as object and now what happened watch it total actually total is 1 0 0 press subject of 0 means 40 later 40 plus 50 later 90 plus 52 like that how many times it is repeated five times nine six times zero two five six times finish it now he is finding the total letter average error is equal to total by six point zero why because totally the integer variable 6 also integer variable an integer 1 integer always gives another integer value for that I am going for integer Y float because of integer Y floater always gives another float that's what to get the accurate value we have to divide with floating value or typecasting required in place of typecasting directly I'm going to use float next now total available here rather is also available now I want to print total average and student pass of ADA that's why first I am going to write like C out first to total T would end nooo total menace and next C out our is a ver is also printed next now I want to find out the result means pass or fail okay for that here how many subjects are there six subjects generally basted on the average we are giving the result means suppose 60% greater than or equal to 60 first class greater than or equal to 50 second class greater than or equal to 35 third class below that failed but here the point is suppose one student aggregate is 80% but one subject is fade then for example then it shows first class that's why I avoid this problem first check all the subject wise marks okay first check all the subject wise marks then go for aggregate that is why here I am going to check the condition if okay here I'm going to write like if already here average rendered here we will render if subject of I and here how many subjects are there six subjects are the total six subjects argot plus I to check the six subjects we have the right subject of 0 subject of one subject of two six times now pair this one once again better to go for int okay here I value I am going to take a value started with zero I less than six IPS place now what happens this for loop is going to repeat 6 times now subject of i/o value means you 0 means this one 0 means greater than or less than okay suppose less than 35 minimum works 35 for subject let's wipe subject off I subject of 0 means 40 40 less than the condition false no problem suppose here I have entered like this 30 seconds ability now 30 less than 35 true when it is to simply and saying see out phase now this sale is going to print the after the result because of cursor is waiting after the return oh that's why the student result is phase okay now one subject is phase in any number of subjects suppose one subject field is total faith that means any number of subjects fail means also failure that's why remaining checking's are not required for the checking third not required that's why I am going to do one small thing here simply I am going to do one thing that is nothing but go to lost that means I am going to use the go to level I am going to use the go to for example it is the last now here something you get CH like this okay program closed now what happens when the subject wise marks are less than that it means in any subject he is getting he or she is getting 35 or less than the differ then automatically see out fail traitor go to loss program jump out to here after that let's H means process completed otherwise okay suppose here student is having 70 now say this 0 subject 44 day less than 35 false 70 less than 35 50 tool and then the difference is T 1 less than that 85 less than the device 71 lism that means no condition that means all the conditions are false that is why directly comes to heels and it feels pass now the pass is going to print here that is why the student result is us okay that's why if a subject he is getting less than 35 it shows fail and later checking is not required that's why go to Las Plus is having message problem stop but suppose if this condition Falls means what and also this unit parcel then also subjects or positivity is going to print directly see out pass later get ch4 oh stop now it is how to find out the student total out and the result okay and now this function also completed here result function also complete later we have to call this program that means we have to invoke the number of functions that so first we have to declare the object when object is there we have to go for main function that's why here I am going to start main function okay see this void we now mean is declared later is tu is now s is the object when object is created memory allocated like this to voids 20 bytes and here 12 hours 16 digits now the side to voice here 20 bytes here and 12 words that's what 42 plus 234 voice memory allocated for this array means this object okay fine later we have to call the member functions yes dot first member function gives two reigned okay when is God gets read in this function it is going to read the student ID name and sick subject marks that means now the sixth circuit marks are stored inside the object later we have to show the reason s dot result when s dot result is called the functioning okay total first of all it is going to find out the total rate that average they are going to bring at last result based on subject now total result also completed and it is completed I am going to close the class because of already here one get CH is there here already get CH is there it is going to stop now now it is going to show the student crystal it is how to use arrays inside the class due to this what is the advantage MIT program size is reduced okay thank you for watching [Music]
Info
Channel: Naresh i Technologies
Views: 47,768
Rating: undefined out of 5
Keywords: Using Array Inside Class, Array Inside Class, Array of Objects in C++, Array, Array of Objects, Objects, C++, C ++ Tutorial, Kishore, Naresh IT
Id: qvtEl-HCwXc
Channel Id: undefined
Length: 16min 22sec (982 seconds)
Published: Fri Apr 07 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.