Home > DeveloperSection > Forums > I need a C plus plus program which is work on
Ankita Pandey
Ankita Pandey

Total Post:183

Points:1285
Posted on    December-05-2012 12:24 AM

 Visual C++ Visual C++ 
Ratings:


 1 Reply(s)
 1795  View(s)
Rate this:
Hi every one

I have a little bit knowledge in C++,

I need a C++ program which is work on:-
1.the key file is automatically generated.
2.Methods for read and write.
3.file and class objects are global.
4.file will open in binary mode.

Thanks


Vijay Shukla

Total Post:100

Points:700
Posted on    December-05-2012 3:30 AM

thats your solution.

#include <iostream.h>
#include<stdio.h>
#include <fstream.h>
#include <conio.h>
#include<stdlib.h>
#include<io.h>
fstream myfile;
class key{
public:
long a;
char b;
void open()
{
char st[50];
int roll,cl;
randomize();
a =100000000 + rand()%10000000;    //generating random no for Key File.
b= 97 + rand()%26;
myfile.open ("student.txt",ios::out | ios::binary);     //opening file in write mode in binary format
cout<<"Enter student name: ";
gets(st);
cout<<"Enter student's roll: ";
cin>>roll;
cout<<"Enter student's class: ";
cin>>cl;
myfile<<"\nStudent name: "<<st;                  
myfile<<"\nStudent's roll: "<<roll;
myfile<<"\nStudent's class: "<<cl;
myfile <<"\nWriting this to a file.\n";
myfile <<"KEY FILE:-"<< b << a<<endl; //writing the key file in your file.
myfile.close();
}
void display()
{
char ch;
cout<<"THE FILE WRITTEN AS:\n\n";
myfile.open("student.txt",ios::in | ios::binary); //opening file in write mode in binary format

while(myfile)
{
myfile.get(ch);
cout<<ch;
}
myfile.close();
}
}stu;




int main() {
int ch;
char c='y';
clrscr();
while(1)
{

cout<<"\nMENU......\n1.WRITE....\n2.READ....\n3.EXIT....\nENTER YOUR CHOICE.....";
cin>>ch;
switch (ch)
{
case 1:
while(c=='y'|| c=='Y')
{ stu.open();
cout<<"Do you want to generate more keys.... Y/N\n";
cin>>c;

}
break;
case 2:
stu.display();
break;
case 3:
exit(0);
default:
cout<<"\nWrong choice entered...";
}
}
getch();
return 0;
}


Don't want to miss updates? Please click the below button!

Follow MindStick