0
#include "stdafx.h"
#include "iostream"
#include "string"

using namespace System;
using namespace std;

class gate
{
public:
    enum mod {single=12,local,global} type;
}gatearry[9];

By repeating the assignment enum values

gatearry[1].type=gate::global;
gatearry[2].type=gate::single;

Instead of above code.

Allocation problem enum values to object class entry.

The difficulty is in using cin in the following loop written in main.

for(i=0;i<9;i++)
{
    cin>>gatearry[i].type;
}
VolAnd
  • 6,367
  • 3
  • 25
  • 43
  • You haven't asked any question. This won't compile passed the 4th line. You have to declare a separate member for `type`. – Barmak Shemirani Aug 22 '16 at 15:01
  • 1
    Possible duplicate of [enum type can not accept cin command](http://stackoverflow.com/questions/10371681/enum-type-can-not-accept-cin-command) – isanae Aug 22 '16 at 16:35
  • Done But there needs to be better – ma.ghorbannejad Aug 23 '16 at 11:54
  • In short: the program itself knows no enumeration names, just as it doesn't know any variable names. They are omitted during compilation. However, you can overload the >> operator to make it work. – Aziuth Aug 23 '16 at 13:59

1 Answers1

0

"This code is written with Visual Studio 10"

Target:

Reduce the commands inside the loop For allocation Enum elements to object class

Or similar and more compact code Such as commands within the loop

#include "stdafx.h"
#include "iostream"
#include "string"

using namespace System;
using namespace std;

class gate
{
    public:
        enum mod {single,local,global} type;
}gatearry[9];

int main()
{
    int i,x=0;
    string d;

    for(i=0;i<9;i++)
    {
        cout<<"\n input gate type"<<i<<"\n";
        cin>>d;
        if (d=="single")
            gatearry[i].type=gate::single;
        else if(d=="local")
            gatearry[i].type=gate::local;
        else if(d=="global")
            gatearry[i].type=gate::global;
        if(gatearry[i].type==gate::global)
            x++;
        cout<<"\n"<<gatearry[i].type;

    }
    cout<<"\n"<<x;
    return 0;
}