[Edited by Kermi3]here's the point: there's no standard way to do what you want to do. I fixed all your logic errors, now it's up to you to find a way to adapt this to your needs:
Code:
//#include <stdio.h> <-- let's stick with C++ here, okay?
//#include <conio.h> <-- let's not use non-standard headers...
#include <iostream>
//the followng declarations are only right because I made them right.
struct pnt;
void prntpnt(struct pnt *p);
void readpnt(struct pnt *p);
struct pnt
{
//public : //it's a struct, things are public by default.
int x;
int y;
char ch;
}; //you forgot your semicolon here
void readpnt(struct pnt *p)
{
std::cout<<"Enter the first value: ";
std::cin>>p->x;
std::cout<<"Enter the second value: ";
std::cin>>p->y;
std::cout<<"Enter the charecter to be entered: ";
std::cin>>p->ch;
}
void prntpnt(struct pnt *p)
{
//gotoxy(p->x,p->y); <-- can we avoid this, please?
//putch(p->ch); <-- maybe you should work out basic data
// structures before moving into stuff
// like this...
std::cout<<"X axis: "<<p->x<<"\nY axis: "<<p->y
<<"\nChar: "<<p->ch<<std::endl;
}
//void main() <-- NO NO NO NO NO NO NO NO NO NO
int main()
{
struct pnt p1; //you declared p2 but never used it
//clrscr(); <-- This is nonstandard, please don't use it
readpnt(&p1);
prntpnt(&p1);
//getch(); //NO.
std::cin.get();
return 0; //returning values is good.
}
[edited by K3]I changed your print and point names because it was the easy way to fix the colors my sytnax highlighter was throwing in there...
and I got bored, so here's an additional "classy" example:
Code:
#include <iostream>
class pnt
{
public:
pnt(const int x=-1,const int y=-1,const char ch='\0');
~pnt();
void readpnt(const int x=-1,const int y=-1,const char ch='\0');
void prntpnt();
private:
int x;
int y;
char ch;
};
pnt::pnt(const int x,const int y,const char ch)
{
this->x=x;
this->y=y;
this->ch=ch;
}
pnt::~pnt(){}
void pnt::readpnt(const int x,const int y,const char ch)
{
if(x==-1)
{
std::cout<<"Enter the X value: ";
std::cin>>this->x;
std::cin.ignore(1);
}
else
{
this->x=x;
}
if(y==-1)
{
std::cout<<"Enter the Y value: ";
std::cin>>this->y;
std::cin.ignore(1);
}
else
{
this->y=y;
}
if(ch=='\0')
{
std::cout<<"Enter the charecter to be entered: ";
std::cin>>this->ch;
std::cin.ignore(1);
}
else
{
this->ch=ch;
}
}
void pnt::prntpnt()
{
std::cout<<"X axis: "<<x<<"\nY axis: "<<y
<<"\nChar: "<<ch<<"\n\n"<<std::flush;
}
int main()
{
pnt p1,p2,p3(10,20,'x');
p2.readpnt(1,2,'3');
p1.readpnt();
p1.prntpnt();
p2.prntpnt();
p3.prntpnt();
std::cin.get();
return 0;
}