Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2026 Crash Course
NEET 2026 Crash Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
824 views
in Computer by (64.2k points)

Answer the question (i) and (ii) after going through the following program:

#include<iostream.h>

#include<string.h>

class Bazar

{  char Type[20];

char Product[20];

int Qty;

float Price;

Bazar() //Fuction 1

{

strcpy(Type,"Electronic");

strcpy(Product,"Calculator");

Qty=10;

Price=225;

}

 public:

voif Disp() //Function 2

{ cout<<Type<<"-"<<Product<<":"<<Qty<<"@"<<Price<<endl;

}

};

void main()

{

Bazar B; //Statement 1

B.Disp(); //Statement 2

}

(i) Will Statement 1 initialize all the data members for object B with the values given in the Function 1? (Yes OR No). Justify your answer suggesting the correction(s) to be made in the above code

 (ii) What shall be the possible output when the program gets executed? (Assuming, if required – the suggested correction(s) are made in the program)

1 Answer

+1 vote
by (69.5k points)
selected by
 
Best answer

(i) No. Since the default constructor Bazar() is declared inside private section, it cannot initialize the objects declared outside the class. Correction needed are:

The constructor Bazar () should be declared inside public section.

(ii) Electronic-Calculator:10@225

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...