1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

hi I wanted some sample C++ programm.

Discussion in 'Meet and Greet' started by ballurohit, Feb 13, 2012.

  1. ballurohit

    ballurohit New Member

    Joined:
    Nov 18, 2011
    Messages:
    43
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    retired
    Location:
    Gujarat
    I wanted some sample c++ programm with a descriptive mode.
     
  2. ballurohit

    ballurohit New Member

    Joined:
    Nov 18, 2011
    Messages:
    43
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    retired
    Location:
    Gujarat
    I desire to learn C++ programming. I can't make out at my own. So please send me some
    sample C++ programms so that I can have an idea how to draw up the programm in c++
    Thanking you sir,

    B.N.ROHIT
     
  3. hobbyist

    hobbyist New Member

    Joined:
    Jan 7, 2012
    Messages:
    141
    Likes Received:
    0
    Trophy Points:
    0
    Sure you can; you just need confidence, patience, determination, and most importantly, you need to create yourself a goal that is just beyond your current skill set. What sort of program are you wanting to make?

    You might ask shabbir to move this into the c++ board.
     
  4. ballurohit

    ballurohit New Member

    Joined:
    Nov 18, 2011
    Messages:
    43
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    retired
    Location:
    Gujarat
    I desire to have programm in database management in which the name of employees, their data just as dob,designation,scale of pay, salary etc.
    so I was thinking how I can create the database structure.
    Thanks.

    B.N.ROHIT
     
  5. ballurohit

    ballurohit New Member

    Joined:
    Nov 18, 2011
    Messages:
    43
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    retired
    Location:
    Gujarat
    I desire to have program in database management in which the name of employees, their data just as dob,designation,scale of pay, salary etc.
    so I was thinking how I can create the database structure.
    Thanks.

    B.N.ROHIT
     
  6. ballurohit

    ballurohit New Member

    Joined:
    Nov 18, 2011
    Messages:
    43
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    retired
    Location:
    Gujarat
    I was thinking to have database management i.e. to keep the data of the employees, their dob, designation, payscale, dor(date of retirement) etc.
    That's all.
     
  7. hobbyist

    hobbyist New Member

    Joined:
    Jan 7, 2012
    Messages:
    141
    Likes Received:
    0
    Trophy Points:
    0
    Do you mean a flat file such as with calling fopen or an actual database program? I don't think I'd be much help beyond maybe a few tutorial links if it's an actual database program.
     
  8. herby

    herby New Member

    Joined:
    Jan 6, 2012
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    hello be specific like "i want a sample and simple program that can..............."
     
  9. herby

    herby New Member

    Joined:
    Jan 6, 2012
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    sorry i've seen the thread but if its a simple data base you may use "fopen" to open th file you want the data but remember 2 open the file for both reading and writing"w+ or r+"
    and then you can use fprintf to write to the file or even "puts"
    then in case of retreiving you use "fread"but it must be logical if this isn't helpful pls let know i''ll give a sample

    otherwise if its for larger databases please opt TRY STAFFS LIKE SQL
     
  10. zachry00

    zachry00 New Member

    Joined:
    Jul 20, 2011
    Messages:
    30
    Likes Received:
    0
    Trophy Points:
    0
    i just want to ask if you have some background in TURBO C??..
     
  11. ballurohit

    ballurohit New Member

    Joined:
    Nov 18, 2011
    Messages:
    43
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    retired
    Location:
    Gujarat
    QUOTEI do have some background in Turbo C. So send me any sample and simple programm in C++.

    B.N.ROHIT UNQUOTE
     
  12. herby

    herby New Member

    Joined:
    Jan 6, 2012
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    ilove to help but please one which does what
     
  13. hobbyist

    hobbyist New Member

    Joined:
    Jan 7, 2012
    Messages:
    141
    Likes Received:
    0
    Trophy Points:
    0
    Have you tried something like

    Code:
    #include <iostream>
    #include <fstream>
    
    typedef struct {
    
        char fname[20];
        char lname[20];
        char title[20];
        char dob[12];
        char rate[8];
    
    } employee;
    
    enum fmodes { F_READ, F_WRITE };
    void fileAccess(std::fstream &, const int &, const int &, employee *);
    
    int main() {
    
        std::fstream f("fdata.txt", std::ios::out | std::ios::binary);
    
        if(!f.is_open()) {
           std::cerr << "Could not open data file";
           return 1;
        }
    
    	f.close();
    	f.clear();
    	f.open("fdata.txt", std::ios::in | std::ios::out | std::ios::binary);
    
    	if(!f.is_open()) {
    	   std::cerr << "Could not open data file";
    	   return 1;
        }
    
        employee *rec = new employee;
        employee edata[] = { { "fname 1", "lname 1", "employee 1", "01/01/1970", "16.30" },
                             { "fname 2", "lname 2", "employee 2", "02/02/1970", "13.60" },
                             { "fname 3", "lname 3", "employee 3", "03/03/1970", "11.90" },
                             { "fname 4", "lname 4", "employee 4", "04/04/1970", "17.10" },
                             { "fname 5", "lname 5", "employee 5", "05/05/1970", "18.50" } };
    
        for(int i=0; i < sizeof(edata)/sizeof(edata[0]); ++i)
           fileAccess(f, F_WRITE, 0, &edata[i]);
    
        f.clear();
    	f.seekg(0, std::ios::end);
    	long user_rec, nrecs = f.tellg() / sizeof(employee);
    
        do {
    
    	   std::cout << "there are " << nrecs << " records, which record would you like to see: ";
    	   std::cin >> user_rec;
           std::cout.flush();
    
    	   if(std::cin.fail()) {
    	      std::cin.clear();
    	      std::cin.ignore(1);
           }
    
    	   while(std::cin.get() != '\n'){}
    
        } while(user_rec <= 0 || user_rec > nrecs);
    
        fileAccess(f, F_READ, user_rec, rec);
    
        std::cout << "\n\nRecord: " << user_rec << std::endl
                  << "  Name: " << rec->fname << " " << rec->lname << std::endl
                  << "   DOB: " << rec->dob << std::endl
                  << "  Rate: " << rec->rate << std::endl
                  << " Title: " << rec->title << "\n\n" << std::endl;
    
        delete rec;
        f.close();
    
        return 0;
    }
    
    void fileAccess(std::fstream &fh, const int &fmode, const int &rec, employee *e) {
    
        fh.clear();
    
        if(fmode == F_READ) {
            fh.seekg((rec - 1) * sizeof(*e));
            fh.read(reinterpret_cast<char *>(e), sizeof(*e));
        } else {
            fh.seekp(0, std::ios::end);
            fh.write(reinterpret_cast<char *>(e), sizeof(*e));
        }
    }
    It's not really a database, but maybe it can offer an idea.
     

Share This Page