CBSE Class 12 Computer Science Classes Objects Constructors And Destructors Worksheet

Class 12 Computer Science Practice Sheet: CBSE Class 12 Computer Science Classes Objects Constructors And Destructors Worksheet

Explore structured practice materials through the CBSE Class 12 Computer Science Classes Objects Constructors And Destructors Worksheet. Tailored for Class 12 learners, utilizing these Computer Science worksheets ensures thorough preparation and strengthens problem-solving accuracy before final school evaluations.

Download Classes Objects Constructors And Destructors Worksheet PDF with Answers

Navigate directly to the solved Computer Science worksheets using the digital viewer below. Each practice set includes detailed step-by-step solutions, allowing students to instantly cross-check their work and identify areas requiring further revision.

Class_12_Computer Science_Worksheet_9

CLASS XII
CLASSES OBJECTS, CONSTRUCTORS & DESTRUCTORS

Question 1. Define a class RESTRA with the following specifications.
Private members: Foodcode (integer), Food (string), Ftype (string), Sticker (string).
A member function Getsticker() to assign the sticker as per the given Ftype:
Vegetarian - Green
Contains Egg - Yellow
Non Vegetarian - Red
Public functions:
A constructor function to assign values for data members as Foodcode is 0, Food and Ftype as null character and Sticker as Green.
A function Getfood() to allow the user to enter values of Foodcode, Food, Ftype and call the function Getsticker() to assign Sticker.
A function Showfood() to allow the user to display the content of all the data members.
Write the main to input one object of RESTRA and display the details.

Answer: #include <iostream>
#include <cstring>
using namespace std;
class RESTRA
{
int Foodcode;
char Food[30], Ftype[30], Sticker[10];
void Getsticker()
{
if (strcmp(Ftype,"Vegetarian")==0) strcpy(Sticker,"Green");
else if (strcmp(Ftype,"Contains Egg")==0) strcpy(Sticker,"Yellow");
else if (strcmp(Ftype,"Non Vegetarian")==0) strcpy(Sticker,"Red");
}
public:
RESTRA() { Foodcode=0; strcpy(Food,""); strcpy(Ftype,""); strcpy(Sticker,"Green"); }
void Getfood()
{
cout<<"Enter Foodcode: "; cin>>Foodcode;
cout<<"Enter Food: "; cin>>Food;
cout<<"Enter Ftype (Vegetarian/Contains Egg/Non Vegetarian): "; cin.ignore(); cin.getline(Ftype,30);
Getsticker();
}
void Showfood()
{
cout<<Foodcode<<" "<<Food<<" "<<Ftype<<" "<<Sticker<<endl;
}
};
int main()
{
RESTRA r;
r.Getfood();
r.Showfood();
return 0;
}

In simple words: The class stores a food item and its type, and automatically picks the colour sticker that matches the type.

Exam Tip: Remember the three Ftype and Sticker pairs, and use strcmp() to compare strings in C++.

 

Question 2. Define a class SPORTS with the following specifications.
Private data members: Name (20 characters), Team (20 characters), Runsscored (long integer), Matches (integer).
Public functions:
Default constructor to initialize members with the values "Dhoni", "India", 25678, 150.
Parameterized constructor that takes an argument r, assigns it to Runsscored and provides other members with valid values.
Copy constructor to assign values of all data members of one object to another object.
chkmatches() function that prints the name of the player if he has played in more than 50 matches.
Displaydetails() function to display all the details of a player.
Destructor to display the message "Destroying object ........"
Write a program to create three objects, one using the default constructor, one using the parameterized constructor and one using the copy constructor (assign the first object to the third object). Print the details of all the three players and display the name of the player who has played in more than 30 matches.

Answer: #include <iostream>
#include <cstring>
using namespace std;
class SPORTS
{
char Name[21], Team[21];
long Runsscored;
int Matches;
public:
SPORTS() { strcpy(Name,"Dhoni"); strcpy(Team,"India"); Runsscored=25678; Matches=150; }
SPORTS(long r) { strcpy(Name,"Virat"); strcpy(Team,"India"); Runsscored=r; Matches=60; }
SPORTS(SPORTS &t) { strcpy(Name,t.Name); strcpy(Team,t.Team); Runsscored=t.Runsscored; Matches=t.Matches; }
void chkmatches() { if (Matches>50) cout<<Name<<endl; }
void Displaydetails() { cout<<Name<<" "<<Team<<" "<<Runsscored<<" "<<Matches<<endl; }
int GetMatches() { return Matches; }
char* GetName() { return Name; }
~SPORTS() { cout<<"Destroying object ........"<<endl; }
};
int main()
{
SPORTS s1;
SPORTS s2(30000);
SPORTS s3(s1);
s1.Displaydetails();
s2.Displaydetails();
s3.Displaydetails();
if (s1.GetMatches()>30) cout<<s1.GetName()<<endl;
if (s2.GetMatches()>30) cout<<s2.GetName()<<endl;
if (s3.GetMatches()>30) cout<<s3.GetName()<<endl;
return 0;
}

In simple words: Each player object stores name, team, runs and matches; the copy constructor makes a full copy of an existing player.

Exam Tip: A copy constructor takes a reference to the same class and copies every data member; the destructor runs when each object goes out of scope.

 

Free CBSE Practice Worksheets: Class 12 Computer Science Classes Objects Constructors And Destructors

Practice Exercises for Class 12 Computer Science Classes Objects Constructors And Destructors

Review targeted practice exercises for Class 12 Computer Science Classes Objects Constructors And Destructors. Curated to match official CBSE guidelines, these printable problem sets support daily revision and improve overall test readiness.

Step-by-Step Solutions and Practice Guidelines

Designed around the official curriculum for Class 12 Computer Science, these practice sheets guarantee standard compliance. Reviewing step-by-step solutions after completion sharpens your accuracy and clarifies complex sub-topics within Classes Objects Constructors And Destructors.

Enhance Speed with Online Practice

Wrap up your chapter revision by testing your knowledge against standard objective question formats. Explore our full library of free, up-to-date printable assignments to maximize your academic results in upcoming CBSE evaluations.

FAQs

Where can I download the 2026-27 CBSE printable worksheets for Class 12 Computer Science Classes Objects Constructors And Destructors?

You can download the latest chapter-wise printable worksheets for Class 12 Computer Science Classes Objects Constructors And Destructors for free from StudiesToday.com. These have been made as per the latest CBSE curriculum for this academic year.

Are these Classes Objects Constructors And Destructors Computer Science worksheets based on the new competency-based education (CBE) model?

Yes, Class 12 Computer Science worksheets for Classes Objects Constructors And Destructors focus on activity-based learning and also competency-style questions. This helps students to apply theoretical knowledge to practical scenarios.

Do the Class 12 Computer Science Classes Objects Constructors And Destructors worksheets have answers?

Yes, we have provided solved worksheets for Class 12 Computer Science Classes Objects Constructors And Destructors to help students verify their answers instantly.

Can I print these Classes Objects Constructors And Destructors Computer Science test sheets?

Yes, our Class 12 Computer Science test sheets are mobile-friendly PDFs and can be printed by teachers for classroom.

What is the benefit of solving chapter-wise worksheets for Computer Science Class 12 Classes Objects Constructors And Destructors?

For Classes Objects Constructors And Destructors, regular practice with our worksheets will improve question-handling speed and help students understand all technical terms and diagrams.