well, i have been working on two projects....
in of the projects i am getting two errors which i am unable to rectify ....please please could you possible identify the two errors for me...?? i shall be really really grateful..
you can try running the below program in Microsoft visual c++ 6.0 and you will see two errors like this :-
(C:\Documents and Settings\Owner\Desktop\project.cpp(206) : warning C4390: ';' : empty controlled statement found; is this the intent?
C:\Documents and Settings\Owner\Desktop\project.cpp(208) : error C2664: 'class istream &__thiscall istream::read(char *,int)' : cannot convert parameter 1 from 'char' to 'char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
C:\Documents and Settings\Owner\Desktop\project.cpp(208) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe.
project.exe - 2 error(s), 1 warning(s)
)
# include<iostream.h>
# include<fstream.h>
# include<stdio.h>
#include<string.h>
void add();
void update();
void delitem();
void search();
void admin();
void cust();
void update();
void csearch();
void purchase();
class mobile
{char modelno[10];
char brand[20];
char specs[100];
float price;
char warranty[10];
public:
void getdata()
{cout<<"enter the brand of the phone"<<endl;
cin.getline(brand,20);
cout<<"enter the model of the phone";
cin.getline(modelno,10);
cout<<"enter the specifications of the phone joined by ','"<<endl;
cin.getline(specs,100);
cout<<"enter the warranty period"<<endl;
cin.getline(warranty,10);
cout<<"enter the price of the phone"<<endl;
cin>>price;
}
void putdata()
{cout<<"BRAND :"<<brand<<endl<<"MODEL :"<<modelno<<endl<<"SPECIFICATIONS :"<<specs<<endl<<"PRICE :Dh"<<price;
}
void getmodelno()
{cout<<modelno;
}
void getbrand()
{cout<<brand;
}
};
class laptop
{ char brand[20];
char lmodelno[10];
int harddisk;
int ram;
char os[20];
char processor[10];
char warranty[10];
int price;
public:
void getlaptop()
{cout<<"enter the brand "<<endl;
cin.getline(brand,20);
cout<<"enter the model number"<<endl;
cin.getline(lmodelno,10);
cout<<"enter the size of the hard disk"<<endl;
cin>>harddisk;
cout<<"enter the ram"<<endl;
cin>>ram;
cout<<"enter the operating system "<<endl;
cin.getline(os,20);
cout<<"enter the processor "<<endl;
cin.getline(processor,10);
cout<<"enter the warranty period"<<endl;
cin.getline(warranty,10);
cout<<"enter the price"<<endl;
cin>>price;
}
void putlaptop()
{cout<<"COMPANY :"<<brand<<endl<<"MODEL :"<<lmodelno<<endl<<"HARD DISK SPACE :"<<harddisk<<"GB"<<endl<<"RAM SIZE :"<<ram<<"GB"<<endl<<"OPERATING SYSTEM :"<<os<<endl<<"PROCESSOR "<<processor<<endl<<"WARRANTY :"<<warranty<<endl<<"PRICE :Dh"<<price;
}
void getmodelno()
{cout<<lmodelno;
}
char getbrand()
{cout<<brand;
}
};
struct date
{
int dd,mm,yy;
};
struct address
{
long int res;
long int mob;
char city[50];
long int pobox;
};
struct name
{
char first[50];
char middle[50];
char last[50];
};
struct creditcard
{
long int first;
long int second;
long int third;
long int fourth;
};
void main()
{int ch;
do
{cout<<"\n menu ";
cout<<"\n WHAT YOU ARE:-";
cout<<"\n 1.ADMINISTRATOR";
cout<<"\n 2.CUSTOMER";
cout<<"\n 3.EXIT";
cout<<"\n ENTER YOUR OPTION"<<endl;
cin>>ch;
switch(ch)
{case 1:admin();
break;
case 2:cust();
break;
}
}while(ch<3);
}
void admin()
{int a;
do
{
cout<<"1.Add";
cout<<"2.Search";
cout<<"3.Update";
cout<<"4.Delete";
cout<<"5.Exit";
cout<<"Enter your option";
cin>>a;
switch(a)
{case 1:add();
break;
case 2:search();
break;
case 3:update();
break;
case 4:delitem();
break;
}
}while(a<5);
}
void add()
{
char option[10];
int n;
mobile m;
laptop l;
fstream fmob,flap;
fmob.open("mobile.dat",ios::out);
flap.open("laptop.dat",ios::out);
cout<<"What u want to add (mobile or laptop)";
cin>>option;
if(strcmpi(option,"mobile")==0)
{
cout<<"\n enter the no. of cells u want to add";
cin>>n;
for(int i=1;i<=n;i++)
{cout<<"enter the details of mobile no:-"<<i;
m.getdata();
fmob.write((char*)&m,sizeof(m));
}
}
else if(strcmpi(option,"laptop")==0)
{cout<<"\n enter the no. of laptops u want to add";
cin>>n;
for(int i=1;i<=n;i++)
{cout<<"enter the details of laptop no:-"<<i;
l.getlaptop();
flap.write((char*)&l,sizeof(l));
}}
else
cout<<"invalid entry"<<endl;
}
void search()
{mobile m;
laptop l;
int found=0;
char model[20],option[20];
fstream fmob,flap;
fmob.open("mobile.dat",ios::out);
flap.open("laptop.dat",ios::out);
cout<<"What u want to search (mobile or laptop)";
cin>>option;
{
if(strcmpi(option,"mobile")==0);
cout<<"enter the model no. u want to search"<<endl;
cin.getline(model,10);
while (fmob.read((char)&m,sizeof(m)));
{if(strcmpi(m.getmodelno(),model)==0)
{found=1;
m.putdata();
break;
}}
if (found==0)
cout<<"no mobile found";
fmob.close();
}
};
else if(strcmpi(option,"laptop")==0);
{cout<<"enter the model no u want to search";
cin.getline(model,10);
while(flap.read((char*)&l,sizeof(l)))
{{if(strcmpi(l.getmodelno(),model)==0)
{found=1;
l.putlaptop();
break;
}
}
if (found==0)
cout<<"no laptop found";
flap.close();
}
else
cout<<"no such item available";
}
void update()
{mobile m;
laptop l;
int found=0;
char model[10],option[20];
fstream fmob,flap;
fmob.open("mobile.dat",ios::out);
flap.open("laptop.dat",ios::out);
cout<<"What u want to update (mobile or laptop)";
cin>>option;
if(strcmpi(option,"mobile")==0)
{cout<<"enter the model no. u want to update"<<endl;
cin.getline(model,10);
while (fmob.read((char)&m,sizeof(m)))
{
if(strcmpi(m.getmodelno(),model)==0)
{found=1;
cout<<"enter the new details";
m.getdata();
fmob.seekp((-1)*sizeof(m),ios::cur);
fmob.write((char*)&m,sizeof(m));
break;
}
}}
else if(strcmpi(option,"laptop")==0)
{cout<<"enter the model no you want to update";
cin.getline(model,10);
while(flap.read((char)&l,sizeof(l)))
{if(strcmpi(l.getmodelno(),model)==0)
{found=1;
cout<<"enter the new details";
l.getlaptop();
flap.seekp((-1)*sizeof(l),ios::cur);
flap.write((char*)&l,sizeof(l));
break;
}
}}
else
cout<<"no such item";
}
void delete();
{mobile m;
laptop l;
int found=0;
char model[10],option[20];
fstream fmob,flap,ftemp;
fmob.open("mobile.dat",ios::out);
flap.open("laptop.dat",ios::out);
ftemp.open("temp.dat",ios::out);
cout<<"What u want to delete (mobile or laptop)";
cin>>option;
if(strcmpi(option,"mobile")==0)
{cout<<"enter the model no. u want to delete"<<endl;
cin.getline(model,10);
while (fmob.read((char*)&m,sizeof(m)))
{if(m.getmodelno()!=model)
ftemp.write((char*)&m,sizeof(m));
}
fmob.close();
ftemp.close();
remove("mobile.dat");
rename("temp.dat","mobile.dat");
}
else if(strcmpi(option,"laptop")==0)
{cout<<"enter the model no. u want to delete"<<endl;
cin.getline(model,10);
while (flap.read((char*)&l,sizeof(l)))
{if(l.getmodelno()!=model)
ftemp.write((char*)&l,sizeof(l));
}
flap.close();
ftemp.close();
remove("laptop.dat");
rename("temp.dat","laptop.dat");
}
else
cout<<"no such item";
}
void cust()
{int ch;
do
{cout<<"1.search our products";
cout<<"2.purchase an item";
cout<<"enter your choice";
cin>>ch;
switch(ch)
{case 1:csearch();
break;
case 2:purchase();
break;
}
}while(ch<3);
}
void csearch()
{mobile m;
laptop l;
int found=0;
char model[10],option[20];
fstream fmob,flap;
fmob.open("mobile.dat",ios::out);
flap.open("laptop.dat",ios::out);
cout<<"What u want to search (mobile or laptop)";
cin>>option;
if(strcmpi(option,"mobile")==0)
{cout<<"enter the model no. u want to search"<<endl;
cin.getline(model,10);
while (fmob.read((char)&m,sizeof(m)))
{if(strcmpi(m.getmodelno(),model)==0)
{found=1;
m.putdata();
break;
}
if (found==0)
cout<<"no mobile found";
fmob.close();
}
}
else if(strcmpi(option,"laptop")==0)
{cout<<"enter the model no u want to search";
cin.getline(model,10);
while(flap.read((char)&l,sizeof(l)))
{if(strcmpi(l.getmodelno(),model)==0)
{found=1;
l.putlaptop();
break;
}
}
if (found==0)
cout<<"no laptop found";
flap.close();
}
else
cout<<"no such item available";
}
void purchase()
{mobile m;
date dl;
address addr;
name customer;
creditcard card;
laptop l;
int found=0,mm,yy,cvc,mfound=0;
char brand[10],option[20];
fstream fmob,flap;
fmob.open("mobile.dat",ios::out);
flap.open("laptop.dat",ios::out);
cout<<"What u want to search (mobile or laptop)";
cin>>option;
if(strcmpi(option,"mobile")==0)
{cout<<"enter the brand u want to search"<<endl;
cin.getline(brand,10);
while (fmob.read((char*)&m,sizeof(m)))
{if(strcmpi(m.getbrand(),brand)==0)
{found=1;
mfound=1;
m.putdata();
}
if (found==0)
cout<<"no such brand";
fmob.close();
}
}
else if(strcmpi(option,"laptop")==0)
{cout<<"enter the brand u want to search";
cin.getline(brand,10);
while(flap.read((char*)&l,sizeof(l)))
{if(strcmpi(l.getbrand(),brand)==0)
{found=1;
l.putlaptop();
}
}
}
if (found==0)
{cout<<"no such brand";
flap.close();
}
else
{ cout<<"do you want to buy";
char yesno[5];
cin.getline(yesno,5);
if(strcmpi(yesno,"yes")==0)
{char model[10];
if(strcmpi(m.getmodelno(),model)==0)
{m.putdata();
}
cout<<"please enter your name";
cout<<"first:";
cin>>customer.first;
cout<<"middle:";
cin>>customer.middle;
cout<<"last:";
cin>>customer.last;
cout<<"enter your address";
cout<<"city:";
cin>>addr.city;
cout<<"pobox:";
cin>>addr.pobox;
cout<<"telephone no.:";
cout<<"residence:";
cin>>addr.res;
cout<<"mobile:";
cin>>addr.mob;
cout<<"enter the date you want to recieve it";
cin>>dl.dd>>dl.mm>>dl.yy;
cout<<"enter your credit card no.";
cin>>card.first>>card.second>>card.third>>card.fourth;
cout<<" enter the expiry date of your card";
cin>>mm>>yy;
cout<<"enter your cvc";
cin>>cvc;
cout<<"your transaction has been confirmed & the amt will be deducted from your card";
cout<<"-----------------------------";
cout<<"-----------------------------";
cout<<"-----------------------------";
cout<<"-----------------------------";
cout<<"invoice";
cout<<"item:";
if(mfound==1)
m.putdata();
else
l.putlaptop();
cout<<" name";
cout<<customer.first;
cout<<customer.middle;
cout<<customer.last;
cout<<" your address";
cout<<"city:";
cout<<addr.city;
cout<<"pobox:";
cout<<addr.pobox;
cout<<"telephone no.:";
cout<<"residence:";
cout<<addr.res;
cout<<"mobile:";
cout<<addr.mob;
cout<<"date of delivery:";
cout<<dl.dd<<dl.mm<<dl.yy;
cout<<" credit card no.";
cout<<"**** **** **** **** "<<card.fourth;
cout<<" expiry date of your card";
cout<<mm<<yy;
cout<<"thank you";
}
}}
ok this is the end of one project......
and here is the other idea about project...which i already discussed before...
this is "typing tutor" but i am stuck with some problems.... the problem is that the user has to enter "0" always to end the thing....if you press enter nothing happens...so please tell me how to do it using "enter" ......and if someone press the "backspace key" then the compiler counts that too.....so how to overcome that problem ....and also if suppose someone write an extra character ..then how to output and count that as error..
#include<iostream>
#include<windows.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include<windows.h>
#include<ctime>
using namespace std;
int main()
{
char text[300]="What goes up must come down";
time_t start,end;
int correct=0,wrong=0;
double dif;
char type;
cout<<"\n Please Enter the given text \n";
Sleep(50);
cout<<text<<endl;
time (&start);
int i=0;
while(type!='0')
{
type=getche();
if(text[i]==type)
correct++;
else
wrong++;
i++;
}
wrong--;
i--;
time (&end);
dif = difftime (end,start);
int speed;
speed= (i*60)/dif;
cout<<"\n You took "<<dif<<" seconds to enter the text";
cout<<"\n Correct = "<<correct;
cout<<"\n wrong = "<<wrong;
cout<<"\n total = "<<i;
cout<<"\n speed = "<<speed<<" characters\\minute";
cout<<"\n accuracy = "<<(correct*100)/i<<" %";
cout<<endl;
return 0;
}