I want proper validation about character or string input at run time.

Please any one help me...........
#include
#include 
#include 
#include 
#include 
#include
#include
class network
{
/* request auto detection */
int gdriver, gmode;
int left, top, right, bottom;
int i,j;
// int isdigit(int i);
char ch;
public:
int ct,rg,s,nr;
//char ct1[];
int a,b;
 
 
int ct1,ct2,ct3,ct4;
void input()
{
cout<<"Enter your requirements: ";
cout<<"\n ";
cout<<"Enter the cost in between 10 to 300 thousands";
 
do
{
cout<<"\n Enter the cost";
cin>>ct;
if((ct<=10||ct>=300))
cout<<"\nINVALID INPUT!!";
}while((ct<=10||ct>=300));
cout<<"Enter range between 4 to 20 mbps";
do
{
cout<<"\n enter the range";
 
cin>>rg;
cin.ignore(INT_MAX,'\n');
if((rg<=4||rg>=20))
cout<<"\nINVALID INPUT!!";
}
while((rg<=4||rg>=20));
do
{
cout<<"\n1.Reliable 2.Nonreliable";
cin>>nr;
if(!(nr==1||nr==2))
cout<<"\nINVALID INPUT!!";
}
while(!(nr==1||nr==2));
do
{
cout<<"\n1.Security 2.No security";
cin>>s;
if(!(s==1||s==2))
cout<<"\nINVALID INPUT!!";
}
while(!(s==1||s==2));
 
}
};
class topology:public network
{
public:
void star();
void mesh();
void ring();
void bus();
void display();
};
 
void topology::star()
{
clrscr();/* draw a rectangle */
ct2=0;
if(ct<200)
ct2++;
if(rg<=10)
ct2++;
if(nr==1)
ct2++;
if(s==1)
ct2++;
cout<<"count2="<
                

Replies

  • Kaustubh Katdare
    Kaustubh Katdare
    #-Link-Snipped-# - are the rest of us expected to guess the question you wish to ask?

    Or, could you please simplify our job by telling us what problem you are facing and what help you expect from our fellow CEans?
  • Badbade Abhi
    Badbade Abhi
    Kaustubh Katdare
    #-Link-Snipped-# - are the rest of us expected to guess the question you wish to ask?

    Or, could you please simplify our job by telling us what problem you are facing and what help you expect from our fellow CEans?
    First Good Morning sir,
    My mini project is on the topology.at the run time entering our requirement then automatically design a topology. if at run time enter requirement in string input then produce lots of error. plz help me
  • Badbade Abhi
    Badbade Abhi
    friends,
    i am Second year engineering student in that semester my mini project is based on Topology design in c++. In that project main goal is at the run time you enter requirement in digit form.When i entering input at run time in digit form then work very well but taking input in character or string form then display lots of error.So i want proper validation about taking string input.
    please can any one help me???? my external project oral is coming in next week.So i will attach my project source code please any one check it and try to make correct if it will work correct then immediately forward me.

    #include
    #include
    #include
    #include
    #include
    #include
    #include
    class network
    {

    int gdriver, gmode;
    int left, top, right, bottom;
    int i,j;
    // int isdigit(int i);
    char ch;
    public:
    int ct,rg,s,nr;
    //char ct1[];
    int a,b;


    int ct1,ct2,ct3,ct4;
    void input()
    {
    cout<<"Enter your requirements: ";
    cout<<"\n ";
    cout<<"Enter the cost in between 10 to 300 thousands";

    do
    {
    cout<<"\n Enter the cost";
    cin>>ct;
    if((ct<=10||ct>=300))
    cout<<"\nINVALID INPUT!!";
    }while((ct<=10||ct>=300));
    cout<<"Enter range between 4 to 20 mbps";
    do
    {
    cout<<"\n enter the range";

    cin>>rg;
    cin.ignore(INT_MAX,'\n');
    if((rg<=4||rg>=20))
    cout<<"\nINVALID INPUT!!";
    }
    while((rg<=4||rg>=20));
    do
    {
    cout<<"\n1.Reliable 2.Nonreliable";
    cin>>nr;
    if(!(nr==1||nr==2))
    cout<<"\nINVALID INPUT!!";
    }
    while(!(nr==1||nr==2));
    do
    {
    cout<<"\n1.Security 2.No security";
    cin>>s;
    if(!(s==1||s==2))
    cout<<"\nINVALID INPUT!!";
    }
    while(!(s==1||s==2));

    }
    };
    class topology😛ublic network
    {
    public:
    void star();
    void mesh();
    void ring();
    void bus();
    void display();
    };

    void topology::star()
    {
    clrscr();/* draw a rectangle */
    ct2=0;
    if(ct<200)
    ct2++;
    if(rg<=10)
    ct2++;
    if(nr==1)
    ct2++;
    if(s==1)
    ct2++;
    cout<<"count2="<
    }
    void topology::mesh()
    {
    clrscr();/* draw a rectangle */
    ct4=0;
    if(ct<300)
    ct4++;
    if(rg<25)
    ct4++;
    if(nr==1)
    ct4++;
    if(s==1)
    ct4++;
    cout<<"count4="<

    }
    void topology::ring()
    {
    clrscr();/* draw a rectangle */
    ct3=0;
    if(ct<100)
    ct3++;
    if(rg<16)
    ct3++;
    if(nr==2)
    ct3++;
    if(s==2)
    ct3++;
    cout<<"count3="<

    }
    void topology::bus()
    {
    clrscr();/* draw a rectangle */
    ct1=0;
    if(ct<50)
    ct1++;
    if(rg<100)
    ct1++;
    if(nr==2)
    ct1++;
    if(s==2)
    ct1++;
    cout<<"count1="<

    }
    void topology::display(void)
    {
    if(ct1 {
    if(ct2 {
    if(ct3 {
    cout<<"\nMESH";
    rectangle(180,130,220,180);
    rectangle(330,130,370,180);
    rectangle(180,280,220,330);
    rectangle(330,280,370,330);
    line(200,280,200,180);
    line(350,280,350,180);
    line(220,305,330,305);
    line(220,155,330,155);
    line(330,280,220,180);
    line(220,280,330,180);
    outtextxy(195,150,"D1");
    outtextxy(340,150,"D2");
    outtextxy(195,300,"D3");
    outtextxy(340,300,"D4");
    outtextxy(230,110,"MESH TOPOLOGY");
    cout<<"\nCHARACTERISTICS OF MESH\n";
    cout<<"\n1.cost=2 to 3 lakh \n2.range=10 to 25 mbps";
    cout<<"\n3.It is reliable \n4.No security";

    }
    else
    {
    cout<<"\nRING";
    rectangle(180,130,220,180);
    rectangle(330,130,370,180);
    rectangle(180,280,220,330);
    rectangle(330,280,370,330);
    circle(275,230,74);
    outtextxy(195,150,"D1");
    outtextxy(340,150,"D2");
    outtextxy(195,300,"D3");
    outtextxy(340,300,"D4");
    outtextxy(230,110,"RING TOPOLOGY");
    cout<<"\nCHARACTERISTICS OF RING\n";
    cout<<"\n1.cost=50 to 100 thousands \n2.range=4 to 16 mbps";
    cout<<"\n3.It is non-reliable \n4.No security";

    }
    }
    else
    {
    if(ct2 {
    cout<<"\nMESH";
    rectangle(180,130,220,180);
    rectangle(330,130,370,180);
    rectangle(180,280,220,330);
    rectangle(330,280,370,330);
    line(200,280,200,180);
    line(350,280,350,180);
    line(220,305,330,305);
    line(220,155,330,155);
    line(330,280,220,180);
    line(220,280,330,180);
    outtextxy(195,150,"D1");
    outtextxy(340,150,"D2");
    outtextxy(195,300,"D3");
    outtextxy(340,300,"D4");
    outtextxy(230,110,"MESH TOPOLOGY");
    cout<<"\nCHARACTERISTICS OF MESH\n";
    cout<<"\n1.cost=200 to 300 thousands \n2.range=10 to 25 mbps";
    cout<<"\n3.It is reliable \n4.No security";

    }
    else
    {
    cout<<"\nSTAR";
    rectangle(130,80,170,130);
    rectangle(280,80,320,130);
    rectangle(130,230,170,280);
    rectangle(280,230,320,280);
    rectangle(205,165,245,190); //center hub
    line(280,231,245,191);
    line(280,131,245,164);
    line(205,165,170,131);
    line(205,191,170,231);
    outtextxy(215,175,"HUB");
    outtextxy(145,103,"D1");
    outtextxy(295,103,"D2");
    outtextxy(145,253,"D3");
    outtextxy(295,253,"D4");
    outtextxy(175,50,"STAR TOPOLOGY");
    cout<<"\nCHARACTERISTICS OF STAR\n";
    cout<<"\n1.cost=100 to 200 thousands \n2.range=5 to 10mbps";
    cout<<"\n3.It is reliable \n4.security";

    }
    }
    }
    else
    {
    if(ct1 {
    if(ct3 {
    cout<<"\nMESH";
    rectangle(180,130,220,180);
    rectangle(330,130,370,180);
    rectangle(180,280,220,330);
    rectangle(330,280,370,330);
    line(200,280,200,180);
    line(350,280,350,180);
    line(220,305,330,305);
    line(220,155,330,155);
    line(330,280,220,180);
    line(220,280,330,180);
    outtextxy(195,150,"D1");
    outtextxy(340,150,"D2");
    outtextxy(195,300,"D3");
    outtextxy(340,300,"D4");
    outtextxy(230,110,"MESH TOPOLOGY");
    cout<<"\nCHARACTERISTICS OF MESH\n";
    cout<<"\n1.cost=200 to 300 thousands \n2.range=10 to 25 mbps";
    cout<<"\n3.It is reliable \n4.No security";

    }
    else
    {
    cout<<"\nRING";
    rectangle(180,130,220,180);
    rectangle(330,130,370,180);
    rectangle(180,280,220,330);
    rectangle(330,280,370,330);
    circle(275,230,74);
    outtextxy(195,150,"D1");
    outtextxy(340,150,"D2");
    outtextxy(195,300,"D3");
    outtextxy(340,300,"D4");
    outtextxy(230,110,"RING TOPOLOGY");
    cout<<"\nCHARACTERISTICS OF RING\n";
    cout<<"\n1.cost=50 to 100 thousands \n2.range=4 to 16 mbps";
    cout<<"\n3.It is non-reliable \n4.No security";

    }
    }
    else
    {
    if(ct1 {
    cout<<"\nMESH";
    rectangle(180,130,220,180);
    rectangle(330,130,370,180);
    rectangle(180,280,220,330);
    rectangle(330,280,370,330);
    line(200,280,200,180);
    line(350,280,350,180);
    line(220,305,330,305);
    line(220,155,330,155);
    line(330,280,220,180);
    line(220,280,330,180);
    outtextxy(195,150,"D1");
    outtextxy(340,150,"D2");
    outtextxy(195,300,"D3");
    outtextxy(340,300,"D4");
    outtextxy(230,110,"MESH TOPOLOGY");
    cout<<"\nCHARACTERISTICS OF MESH\n";
    cout<<"\n1.cost=2 to 3 lakh \n2.range=10 to 25 mbps";
    cout<<"\n3.It is reliable \n4.No security";

    }
    else
    {
    cout<<"\nBUS";
    outtextxy(230,110,"BUS TOPOLOGY");
    rectangle(180,130,220,180);
    rectangle(305,130,345,180);
    rectangle(245,230,285,280);
    rectangle(365,230,405,280);
    line(155,205,430,205);
    line(155,206,430,206);
    line(155,207,430,207);
    line(200,205,200,180);
    line(265,205,265,230);
    line(325,205,325,180);
    line(385,205,385,230);
    outtextxy(194,150,"D1");
    outtextxy(318,150,"D2");
    outtextxy(259,250,"D3");
    outtextxy(379,250,"D4");
    cout<<"\nCHARACTERISTICS OF BUS\n";
    cout<<"\n1.cost=10 to 50 thousands \n2.range=10 to 100 mbps";
    cout<<"\n3.It is non-reliable \n4.No security";

    }
    }
    }
    cout<<"\n-------USERS REQUIREMENT:-------";
    cout<<"\nCOST= "< cout<<"\nRANGE="< if(nr==1)
    cout<<"\nRELIABLE";
    else
    cout<<"\nNON-RELIABLE";
    if(s==1)
    cout<<"\nSECURITY";
    else
    cout<<"\nNO SECURITY";
    cout<<"\ncount1: "< cout<<"\ncount3: "< }

    int main(void)
    {
    /* request auto detection*/
    int gdriver = DETECT, gmode, errorcode;
    int left, top, right, bottom;
    int i;
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
    setbkcolor(BLACK);
    textcolor(BLACK);
    clrscr();
    cout<<"\n\t\t-----MINI PROJECT ON NETWORK TOPOLOGY-----\n";
    setcolor(RED);
    // clrscr();
    topology a;
    a.input();
    a.bus();
    a.star();
    a.ring();
    a.mesh();
    a.display();

    getch();
    closegraph();
    return 0;
    }
  • Vishal Sharma
    Vishal Sharma
    Dude!

    better write comments in your code.. Makes it understandable..

    try type casting like
    (int)(ch - '0')

    i think it will work fine.. it'll convert your input numeric character to an integer! ch is your input(not tested.. hope it works)
  • rahul69
    rahul69
    Badbade Abhi
    First Good Morning sir,
    My mini project is on the topology.at the run time entering our requirement then automatically design a topology. if at run time enter requirement in string input then produce lots of error. plz help me
    Simply use character arrays to store values instead of integers,then convert that character array to integer using atoi() Eg:
    char ct[max];
    int n;
    .
    .
    cin>>ct;
    n=atoi(ct);
    
    It should solve your problem. Good Luck!!👍
  • Badbade Abhi
    Badbade Abhi
    Vishal0203
    Dude!

    better write comments in your code.. Makes it understandable..

    try type casting like
    (int)(ch - '0')

    i think it will work fine.. it'll convert your input numeric character to an integer! ch is your input(not tested.. hope it works)
    dear sir,
    if you have lots of time then please try to solve my problem because my external oral is coming on Friday. please sir help me.
    I hope you help me.
  • Kaustubh Katdare
    Kaustubh Katdare
    Badbade Abhi
    dear sir,
    if you have lots of time then please try to solve my problem because my external oral is coming on Friday. please sir help me.
    I hope you help me.
    As #-Link-Snipped-# said, please add comments to your code so that it's easier for others to understand and help you out with the problem. 😀
  • SDKING
    SDKING
    #-Link-Snipped-#-Plz Add comments in your code so we understood your problem...and try to solve your problem.. dont take tens...ALL IS WELL....I also 2nd year Stud...And i m Also Done My mini Project.....So add comments in your code then We could help u....😀
  • Vishal Sharma
    Vishal Sharma
    I tried compiling your project.. I think you use the blue screen editor and hence got a lot of compilation errors.. I have some problem with my graphics.h so i'll rectify it first.. till that time, you have a look at Tips For C++ Programmers - Read & Learn

    You'll understand what you need to change in your code...

You are reading an archived discussion.

Related Posts

hey guys i will highly recommend to watch the minute physics channel in youtube.. its amazing with its catchy doodlin and quick n precise info
this process done for the enhancement of automobiles seem to be interesting.. can anyone explain the mechanism?
getting into the iit's is a dream come true for apirants..but the so called one of the toughest exams on earth just deal with mere intelligence..i think some people may...
The Engineering Screw Chart is a product of the Great Innovations Team. It includes technical information from many of the quick references that are commonly found in the work areas...
Because you'll want to use it more often. Make sure there are no key-jams. You've been informed. Okay? Update : We just can't wait! We've launched something cool and it's...