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
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.
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
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
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.
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.
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
QUOTEI do have some background in Turbo C. So send me any sample and simple programm in C++. B.N.ROHIT UNQUOTE
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.