C++ programming language part- 70 More abuot Integer Input and Output
More
abuot Integer Input and Output
In the program 47_3, write()
function has used. Here, &p is the address of the variable. The (char*) is
a type cast. The type cast is required because the first parameter to both
read() and write() function is a character pointer. So the address of the
object has to be type cast to a character pointer. The process is int a; char b[5]; b=(char*) &a; the other is
int=a,b; b=sizeof(a);
Think about the following program
Program 47_9
//inherit.demo
#include
#include
class
customer //class defined
{
char cname[21];
int no_people;
char ccat;
float fcost;
char cstart_date[9];
public:
void data_in()
{
cout<<"Type name \t";
cin>>cname;
cout<<" Type number of people
\t";
cin>>no_people;
cout<<"Type catagory(N/S)
\t"; // Normal or Special
cin>>ccat;
cout<<"Type the cost \t";
cin>>fcost;
cout<<"Type start date \t";
cin>>cstart_date;
}
void data_out()
{
cout<<"name is=
"<
cout<<"No of people are =
"<
cout<<"catagory is =
"<
cout<<"cost is =
"<
cout<<"start date is =
"<
}
};
class custfile
{
customer c1;
public:
void data_in()
{
char creply;
fstream
fil("custfile.dat",ios::out); //ios::app
do
{
c1.data_in();
fil.write((char*)&c1,sizeof(c1)); //The (char*) is a type cast, The &c1
is address
cout<<"wish to continue ";
cin>>creply;
}
while (creply=='y');
}
void data_out()
{
char creply;
fstream
fil("custfile.dat",ios::in); //ios::app
fil.read((char*)&c1,sizeof(c1));
while (fil)
{
c1.data_out();
fil.read((char*)&c1,sizeof(c1));
}
}
};
void main()
{
custfile cf1;
cf1.data_in();
cf1.data_out();
}
Part- 86 assign the content of twostring
জ্ঞানকোষ প্রকাশনী
৩৮/২-ক, বাংলাবাজার (২য় তলা), ঢাকা।
ফোনঃ ৭১১৮৪৪৩, ৮১১২৪৪১, ৮৬২৩২৫১.
কলকাতায় পরিবেশক/প্রাপ্তিস্থান
রিতা ইন্টারন্যাশনাল
৩৬, পি.এন. ব্যানার্জি রোড, কলকাতা
ফোনঃ ২৫১৩৮৩৫৯, ৯৮৩০৪৩৯৬৭৯, +৯১৯৮৩০৪৩৯৬৭৯