I NEED A C PLUS PLUS PROGRAM WHICH IS WORK ON

Ankita Pandey

Total Post:183

Points:1285
Posted by  Ankita Pandey
 2138  View(s)
Ratings:
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
  1. Vijay Shukla

    Post:100

    Points:700
    Re: I need a C plus plus program which is work on

    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;
    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!