شرح ع كلاس class للغة c++
اسئله عن موضوع كلاس class للغة c++
Lab 4: Using different handles to access class members,and Writing and using destructors.
Lab Objectives:
ü Understand class scope and accessing class members via the name of an object, a reference to an object or a pointer to an object.
ü Writing and using destructors to perform "termination housekeeping" on an object before it is destroyed.
ü Declaring local, global, and static local objects.
ü Learn when constructors and destructors are called and the order in which they are called.
ü Defining utility functions.
Student Learning Outcomes:
You will:
ü Be able to use object name or a reference to an object or a pointer to an object to access different class members.
ü Be able to declare destructor for any class to perform termination housekeeping.
ü Be able to identify the order in which the constructors and destructors are called for a set of objects (which have different storage classes (automatic or static) and different scopes (local and global)).
ü Be able to write utility function and use it.
Background:
You have learned the basic concept of using handlings to access class members. You have also learned how to write a destructor for a given class.
You have also known what the utility function is.
Assumption:
Read the summary in page#14from the CS118 lab Manual that explains the Order of constructor, destructor function calls for global, static, and local objects.
LIST OF Exercises:-
Exercise #1:
Write a full documented and separated interface C++ program that implements a class called Student, giving the specification below:
Data that is associated with a Student class:
o An array to hold the marks of the student for five courses.
o Name: of type string to hold student name.
Functions that can be performed on Student class:
o Parameterized constructor to initialize object data members to any given values.
o Destructor: that just prints the message “Class Student Destructor”.
o SetAll function: to assign new values to the data members.
o Utility function to calculate the summation of student marks.
o Access function called Average: to calculate the average of the student marks.
o Access function called Print: to print the information of the student.
Write a driver program that test class Student as follows:
o Define an object of type student named s1, a pointer to s1 named ptr1, and a reference to s1 named ref1.
o Change the values of s1 by calling the function setAll using the reference ref1.
o Compute the average of s1 using the pointer ptr1.
o Print the information of s1.
Exercise #2:
Write a class implementation for a class named My_Class giving the specification below:
Data that is associated with this class are:
o ID: of type integer.
o Msg: of type string, to hold a simple description of any created object (local, global, static, or automatic).
Member Functions:
o Constructor with 2 arguments to:
§ Initialize object data members ID and Msg with any given value, and print the following statement
cout<<”constructor ”<<ID<<”\t”<<Msg<<endl;
o Destructor to:
§ print the ID and Msg of any terminated object as follow:
cout<<”Destructor ”<<ID<<”\t”<<Msg<<endl;
Also you have to write (outside the class):
o A global void function named Create_Fun( ) that declares 2 objects:
obj1: local automatic to Create_Fun ( ).
obj2: static local to Create_Fun ( ).
Hint: Use the following code:
void create_Fun()
{
cout<<"\n create Function:Excution Begin"<<endl;
my_class obj1(1,"Local to Create fun ");
static my_class obj2(2,"Static Local to Create fun ");
cout<<"\n create Function:Excution END"<<endl;
}
Write a driver program that test the class as follow:
1) Declare a global object named obj3.[id=3 , msg=”Global]
2) Declare a local object to the main function named obj4.
[id=4 , msg=”local to main”]
3) Declare a static local object to the main function named obj5.
[id=5 , msg=”static local to main”]
4) Call function Create_Fun ( ) from the main function.
5) Declare a local object named obj6 to the main function.
[id=6, msg="local to main”]
6) Make another Call for function Create_Fun ( ) from the main function.
7) Declare a local object named obj7 to the main function.
[id=7, msg="local to main”]
مع شركة عزل خزانات المياه ستضمن عملية عزل بطريقة علمية وصحية مطابقة للمواصفات العالمية وسنعطيك ضمان شامل فى حالة وجود اي مشكلات قد تطرأ بعد الانتهاء من العزل
ردحذفعزل خزانات بالمدينة المنورة فشركتنا تعد من أفضل شركات عزل الخزانات وسر براعتها فى هذا المجال هو إعتماد عزل خزانات بالمدينه المنوره على فريق عمل متخصص فى كيفية إستخدام الطرق والأدوات الحديثة لعزل الخزانات والعمل على طهارتها من أي شوائب توجد بها،واهم ما يميز
عزل خزانات بالمدينه المنوره عن شركات عزل الخزانات بالمدينة المنورة فإنها تقدم لك أفضل الخدمات وبأسعار مناسبة جدا .فإذا كان لديك خزانا تجد صعوبة بالغة فى تنظيفه فإليك عزل خزانات المياه سوف تقوم بمساعدتك على هذه المشكلة وفى أسرع وقت ممكن وذلك بتقديم أفضل الحلول
شركة عزل خزانات بالمدينة المنورة وفقا لمعايير دقيقة لديها لضمان إتمام عملية العزل بنجاح.