My Computer Forum Computer Science Forum

Go Back   My Computer Forum > Computer Science Forum > Programming

Programming Programming Languages, Interpreters, and Compilers - Assembly, Declarative, Machine, Object Oriented, Iterative


Reply
 
LinkBack Thread Tools Display Modes
June 17th, 2010, 07:57 PM   #1
 
Joined: May 2010
Posts: 23
C++ program code, need help with this C++ application.

Okay! I've been trying to create this application for 5days and still it always creates some problems.

I have to create a program in which User enters the records of different person (like name, age and S.no.) and then it writes the thing to a .dat file.
Also, user can modify the records and even delete them.

I don't know how to create this application. I tried combination of different functions, classes and loops but nothing worked.

Pleas try to make program using classes and functions.

I know it is a big thing to ask here, but I need your help. So, pleas help me. I need this code.

Here is the code I was trying to create which wasn't working.

Code:
//wprec.cpp
#include <iostream.h>
#include <stdio.h>
#include <conio.h>
#include <fstream.h>
class object
{
public:
char name[50];
int age, roll,modroll;
public:
void addpers();
void showpers();
/*cout<<"\n\nName of the person"<<name;

getch();
}*/
void modpers();
}pwr;
void object::showpers()
{
fstream f1;
f1.seekg(0,ios::beg);
while(!f1.eof())
{
f1.read((char *)&pwr,sizeof(pwr));
 cout<<"\nAge:"<<age;
cout<<"\nRoll no:"<<roll;
cout<<"\nPress any key to continue...";
 if(f1.eof())
 break;
 }
 }
void object::modpers()
{
fstream file;
int pos;
int count;
count=0;
cout<<"\nEnter the roll number of the person you want to modify records for...";
cin>>modroll;
file.seekg(modroll,ios::beg);
//while(file.read((char *)&pwr,sizeof(pwr)))
//{
//if(modroll==roll){
cout<<"Enter the name";
fflush(stdin);
gets(name);
cout<<"\nEnter the roll no";
cin>>roll;
cout<<"\nEnter the age...";
cin>>age;
pos=count*sizeof(pwr);
file.seekp(pos,ios::beg);
file.write((char *)&pwr,sizeof(pwr));
//}
//count++;
//}

}
void object::addpers()
{
cout<<"Enter the information of the person."<<endl;
cout<<"Enter full name of the person...";
fflush(stdin);
gets(name);
cout<<"\nEnter the age of the person...";
cin>>age;
cout<<"\nEnter the roll no. of the person...";
cin>>roll;
}
void main()
{
char ch;
clrscr();
object pwr;
int op;
fstream infile;
infile.open("D:\WPREC.DAT",ios::in|ios::app);
do
{
cout<<"1. addition of records\n" ;
cout<<"2. modification of records\n";
cout<<"3. deleation of records\n";
cout<<"\nEnter an option...";
cin>>op;
switch(op)
{
case 1: pwr.addpers();
break;
case 2: pwr.modpers();
break;
}
infile.write((char *)&pwr,sizeof(pwr));
cout<<"Want to rework on the project...y/n?";
fflush(stdin);
cin>>ch;
}while(ch=='y');
//{
/*infile.seekg(0,ios::beg);
infile.read( (char *)&pwr, sizeof(pwr) );
while(!infile.eof())
{
cout<<"\nPerson:";
//pwr.showpers();
infile.read( (char *) &pwr, sizeof(pwr) );
pwr.showpers();
}
//}*/
pwr.showpers();
}
chetanbhasin is offline  
 

My Computer Forum is free to register and we welcome everyone!

Reply

  My Computer Forum > Computer Science Forum > Programming

Tags
application, code, program



Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
simple pari-GP code question billymac00 Programming 0 November 8th, 2013 05:32 AM
Best Screencasting Program Nerazzurri_KZ Computer Science 3 July 11th, 2012 03:55 AM
Javascript to CSS code bulf Tech Support 1 December 18th, 2011 02:42 PM
C code bummer greg1313 Programming 2 July 13th, 2010 03:11 PM
genetic code setayesh94 Computer Science 0 February 6th, 2010 04:33 AM





Copyright © 2018 My Computer Forum Forum. All rights reserved.