Write a C++ program that will enter the Name, Age, and Gender of a student. Test the Gender and Age. If Age is greater than or equal to 18, display the Name, followed by the remarks. "The student is a (male/female) voter", otherwise, display, "The student is a (male/female) non-voter".
1
Expert's answer
2013-02-14T08:53:54-0500
# include <iostream> # include <string > using namespace std;
class stud{ private: string name; int age; bool gen;//1-boy public: void in(){ cout<<"Name:"; getline(cin,name,'\n'); cout<<"age:"; cin>>age; cout<<"Gender: 1- male, 0- female"; cin>>gen; } void print(){ if ( gen==1){ cout<<"The student is a male "; if (age>=18) cout<<"voter\n"; else cout<<"non-voter\n";
} else {cout<<"The student is a female "; if (age>=18) cout<<"voter\n"; else cout<<"non-voter\n"; } }
}; int main(){ setlocale( LC_ALL,"Russian" ); stud a; a.in(); a.print();
Comments
Leave a comment