Computer Science, asked by affifurrahman, 10 months ago

Mr.Sam is working as a science teacher at Aadharsh CBSE School. Every year admission is happening in all schools. In the time of admission, all teachers should write a student's age, first name, last name, and standard in the paper. But, it's very difficult to manage it. The same problem was faced by Sam and he needs to develop an application that has a class named Student and consisting of student's age, first name, last name, and standard. Help Mr.Sam to develop an application using structure. Note: It's a common practice to make all variables private, and set/get them using public methods. Create the following methods. Method named getage() without any parameters, it needs to return the value of the age field. Method named getfirstname() without any parameters, it needs to return the value of the firstName field. Method named getlastname() without any parameters, it needs to return the value of the lastName field. Method named getstandard() without any parameters, it needs to return the value of the standard field. Method named setage() with one parameter of type integer, it needs to set the value of the age field. If the parameter is less than 6 or greater than 17, it needs to set the age field value to 0. Method named setfirstname() with one parameter of type String, it needs to set the value of the firstname field. Method named setlastname() with one parameter of type String, it needs to set the value of the lastname field. Method named setstandard() with one parameter of type int, it needs to set the value of the standard field. If the parameter is less than 1 or greater than 12, it needs to set the standard field value to 0. Also you have to create another method to_string() which returns the string consisting of the above elements, separated by a comma(,). Input Format Input will consist of four lines. The first line will contain an integer, representing the age. The second line will contain a string, representing the first_name of a student. The third line will contain another string, representing the last_name of a student. The fourth line will contain an integer, representing the standard of student. Note: The number of characters in first_name and last_name will not exceed 50. Output Format: Output will be of a single line, consisting of age, first_name, last_name and standard, each separated by one white space. If the parameter of age and standard are equal to 0, then print "No Admission"; Sample Input: 15 Jack Khan 10 Sample Output: 15 Khan, Jack 10 15,Jack,Khan,10

Answers

Answered by reddyyashodhara
1

Answer:

#include<iostream>

using namespace std;

class Student

{

 public:

 int age, stan;

 string fname, lname;

 void setage(int age)

 {

   if(age<6 || age>17)

     age =0;

 }

 void setfirstname(string fname)

 {

 }

 void setlastname(string lname)

 {

 }

 void setstandard(int stan)

 {

   if (stan<1 || stan>12)

     stan =0;

 }

 void getage();

 void getfirstname();

 void getlastname();

 void getstandard();

 void to_string()

 {

   if(age <6 || age>17 || stan<1 || stan>12)

     cout<<"No Admission";

   else

   {

     cout<< age<<"\n"<<lname<<", "<<fname<<"\n"<<stan<<"\n"<<"\n";

     cout<<age<<","<<fname<<","<<lname<<","<<stan;

   }

 }

};

int main()

{

 Student s;

 cin>>s.age>>s.fname>>s.lname>>s.stan;

 s.to_string();

 return 0;

}

Explanation:

All test cases passed

Similar questions