I write a program with class for a student and add a overloading operator= but i have many error in it plzzzzzzzzzzz
help
#ifndef STRING1_H
#define STRING1_H
#include %26lt;iostream.h%26gt;
class String{
public:
String %26amp;operator=(const String %26amp;);//assign array
private:
char * s;};
#endif
#include%26lt;iostream.h%26gt;
#include%26lt;iomanip.h%26gt;
#include%26lt;stdlib.h%26gt;
#include%26lt;assert.h%26gt;
#include%26lt;string1.h%26gt;
#include%26lt;stdio.h%26gt;
#include%26lt;conio.h%26gt;
#include%26lt;string.h%26gt;
String %26amp;String::operator=(const String %26amp; str){
strcpy(string,str.string);
return *this;
}
#include"string1.h"
#include%26lt;stdio.h%26gt;
#include%26lt;conio.h%26gt;
#include%26lt;string.h%26gt;
#include%26lt;stdlib.h%26gt;
#include%26lt;iostream.h%26gt;
class student{
char id[13];
char id1[13];
//int min ;
//int hour;
// char ch;
char time1[7];
char time[7];
//char time[7];
char name[30];
char name1[30];
char address[50];
char address1[50];
char date[13];
char date1[13];
int h;
public:
student();
void ID();
void NAME();
void Address();
void Time();
void Date();
void change();
void print();
}t;
student::student(){
id1[0]='8';
id1[1]='4';
id1[2]='4';
id1[3]='4';
id1[4]='1';
id1[5]='1';
id1[6]='0';
id1[7]='0';
id1[8]='1';
id1[9]='0';
id1[10]='5';
address1[0]='d';
address1[1]='u';
address1[2]='b';
address1[3]='a';
address1[4]='i';
name1[0]='m';
name1[1]='a';
name1[2]='h';
name1[3]='y';
name1[4]='a';
time1[0]='1';
time1[1]='0';
time1[2]=':';
time1[3]='3';
time1[4]='4';
date1[0]='1';
date1[1]='9';
date1[2]='9';
date1[3]='8';
date1[4]='/';
date1[5]='1';
date1[6]='0';
date1[7]='/';
date1[8]='1';
date1[9]='2';
// f[0]='j';
// f[1]='o';
//f=new char[4];
}
void student::ID(){
int c=0;
for(int i=0;i%26lt;11;i++){
if(id1[i]-48%26lt;10%26amp;%26amp;id1[i]-48%26gt;-1 )
c++;
}
if(c==11){
for(int k=0;id1[k];k++)
id[k]=id1[k];
cout%26lt;%26lt;"ID:"%26lt;%26lt;id%26lt;%26lt;endl;}
else
cout%26lt;%26lt;"you enter wrong number"%26lt;%26lt;endl;
}
void student::NAME(){
int c=0;
for(int i=0;name1[i];i++){
if((name1[i]%26gt;='a'%26amp;%26amp;name1[i]%26lt;='z')||... ' )
c++;}
if(name1[c]=='\0'){
for(int k=0;name1[k];k++)
name[k]=name1[k];
cout%26lt;%26lt;"NAME:"%26lt;%26lt;name%26lt;%26lt;endl; }
else
cout%26lt;%26lt;"you enter wrong name"%26lt;%26lt;endl;
}
void student::Address(){
int c=0;
for(int i=0;address1[i];i++){
if((address1[i]%26gt;='a'%26amp;%26amp;address1[i]%26lt;=... ' )
c++;}
if(address1[c]=='\0'){
strcpy(address,address1);
cout%26lt;%26lt;"Address:"%26lt;%26lt;address%26lt;%26lt;endl; }
else
cout%26lt;%26lt;"you enter wrong number"%26lt;%26lt;endl;
}
void student::Time(){
int c=0;
int i=0,j=0,m;
for(;time1[i];i++){
if(time1[i]==':'){
c++;j=i; }}
if(c==1%26amp;%26amp;j%26gt;0){
if(j==1)
h=time1[0]-48;
else if(j==2)
h=(time1[0]-48)*10+(time1[1]-48);
if(i-j-1==1)
m=time1[j+1]-48;
else if(i-j-1==2)
m=(time1[j+1]-48)*10+(time1[j+2]-...
}
else
cout%26lt;%26lt;"you write wrong time"%26lt;%26lt;endl;
if(h%26lt;25%26amp;%26amp;h%26gt;0%26amp;%26amp;m%26lt;60%26amp;%26amp;m%26gt;-1){
strcpy(time,time1);
cout%26lt;%26lt;"Time: "%26lt;%26lt;time;
if(h%26lt;12)
cout%26lt;%26lt;" AM"%26lt;%26lt;endl;
else
cout%26lt;%26lt;" PM"%26lt;%26lt;endl;
}
else
cout%26lt;%26lt;"you write wrong time"%26lt;%26lt;endl;
}
void student::Date(){
int M=0,Y=0,D=0,i,j,c=1,c1=1,c2=1;
for( i=0;date1[i];i++)
j=i;
while(j%26gt;=0){
if(date1[j]=='/'){
if(j!=4%26amp;%26amp;j!=7%26amp;%26amp;j!=6){
cout%26lt;%26lt; "you enter wrong year";
break;}
j--;}
if (date1[j]-48%26gt;-1%26amp;%26amp;date1[j]-48%26lt;10%26amp;%26amp;(date1[...
M=(date1[j]-48)*c1+M;
c1*=10;
}
else if (date1[j]-48%26gt;-1%26amp;%26amp;date1[j]-48%26lt;10%26amp;%26amp;(date1[...
Y=(date1[j]-48)*c2+Y;
c2*=10;
}
else if(date1[j]-48%26gt;-1%26amp;%26amp;date1[j]-48%26lt;10){
D=(date1[j]-48)*c+D;
c*=10;
}
else
break;
j--;
}
if(D%26gt;0%26amp;%26amp;D%26lt;31%26amp;%26amp;M%26gt;0%26amp;%26amp;M%26lt;7%26amp;%26amp;Y%26gt;1880%26amp;%26amp;Y%26lt;...
strcpy(date,date1);
cout%26lt;%26lt;"DATE:"%26lt;%26lt;date;}
else if(D%26gt;0%26amp;%26amp;D%26lt;32%26amp;%26amp;M%26gt;6%26amp;%26amp;M%26lt;13%26amp;%26amp;Y%26gt;1880%26amp;%26amp;Y%26lt;2008)...
strcpy(date,date1);
cout%26lt;%26lt;"DATE:"%26lt;%26lt;date;}
else
cout%26lt;%26lt;"you enter wrong DATE";
}
void student::change(){
int I,i=0;//h,m;
cin%26gt;%26gt;I;
switch(I){
case 1:
gets(id1);
ID();
break;
case 2: gets(name1);
NAME();
break;
case 3:gets(address1);
Address();
break;
case 4:
gets(time1);
Time();
break;
case 5: gets(date1);
Date();
break;
default: exit(0);
}
}
void student::print(){
cout%26lt;%26lt;"ID:"%26lt;%26lt;id%26lt;%26lt;endl;
cout%26lt;%26lt;"NAME:"%26lt;%26lt;name%26lt;%26lt;endl;
cout%26lt;%26lt;"Address:"%26lt;%26lt;address%26lt;%26lt;endl;
cout%26lt;%26lt;"Time: "%26lt;%26lt;time;
if(h%26lt;12)
cout%26lt;%26lt;" AM";
else
cout%26lt;%26lt;" PM";
cout%26lt;%26lt;endl%26lt;%26lt;"Date:"%26lt;%26lt;date;
}
main(){
clrscr();
t.ID();
t.NAME();
t.Address();
t.Time( );
t.Date();
char s1("happy"),s2;
cout%26lt;%26lt;"assigment";
s2=s1;
cout%26lt;%26lt;"s1"%26lt;%26lt;s1;
cout%26lt;%26lt;"s2"%26lt;%26lt;s2;
/* cout%26lt;%26lt;endl%26lt;%26lt;"preess 0 to change"%26lt;%26lt;endl%26lt;%26lt;"press any key for exit";
int j=-1;
cin%26gt;%26gt;j;
while(j==0){
if(j==0){
cout%26lt;%26lt;"1.id 2.name 3.address 4.time 5.Date";
t.change();
}
getch();
clrscr();
t.print();
cout%26lt;%26lt;endl%26lt;%26lt;"preess 0 to change"%26lt;%26lt;endl%26lt;%26lt;"press any key for exit";;
cin%26gt;%26gt;j;
} */
}
Plzzzzzzzzzzzzzzzzzzz help in programming plzzzzzzzzzzzzz?
How does this even compile:
String %26amp;String::operator=(const String %26amp; str){
strcpy(string,str.string);
return *this;
}
what is string? You don't have that declared anywhere.
Reply:did this work at some point?
Reply:Yes, it may have an error in it.
Reply:i'm not gonna simulate this program.report abuse if you like.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment