Create a student class which has following functionality:

  • Initialise a student with mandatory parameters
  • Create a student with name, email and phone number
  • Add a list of subjects based on which class he is
  • Add a function to calculate his percentage based on marks scored

I have written C++ code of student database. I want python code so please anyone write in python and share asap.
Thanks in advance :-)

JamesCherrill commented: If you want someone to do your homework then you've come to the wrong place. -3

You neglected to add bullet point 4

  • Post your code so I don't have to do anything myself
commented: OP may be management material. +15

Please send your mail id @Reverend Jim, because I am not able to upload that file here. Help me to writing the same it in python. Thank you.

Here is the code screenshots. Thank you.

pic1.png

pic2.png

As above, use the </> Code Block feature when posting otherwise you end up with fuzzy hard to read pictures that no one can copy, edit and paste their ideas.

It also makes it possible to (in some cases) copy/paste code if someone wants to do local testing to help you out.

Sorry for the inconvenience.
PFA.

@san. The code will fit inside your post. Why would you have us open up Word or other apps to get at your code.

Again, when you post use the </> Code Block so your code is here and ready to read. Make it easy on everyone.

        < = {
        > = }
        ******Here is the code*****
        #include <iostream>
        using namespace std;

        #define MAX 10

        class student
        <
            private:
                char  name[30];
                int   rollNo, mobile_number;
                char  email[50];
                int   section;
                char  subjects[15];
                int   total;
                float perc;
            public:
                //member function to get student's details
                void getDetails(void);
                //member function to print student's details
                void putDetails(void);
        >;

        //member function definition, outside of the class
        void student::getDetails(void){
            cout << "Enter name: " ;
            cin >> name;
            cout << "Enter roll number: ";
            cin >> rollNo;
            cout << "Enter mobile number: ";
            cin >> mobile_number;
            cout << "Enter email: ";
            cin >> email;
            cout << "Enter class of student: ";
            cin >> section;
            cout << "Enter subjects of class: ";
            cin >> subjects;
            cout << "Enter total marks out of 600: ";
            cin >> total;

            perc=(float)total/600*100;
        >

        //member function definition, outside of the class
        void student::putDetails(void){
            cout << "Student details:\n";
            cout << "Name:"<< name << "\nRoll Number:" << rollNo << "\nMobile Number:" << mobile_number << "\nemail-id:" << email << "\nSection:" << section << "\nSubjects:" << subjects << "\nTotal:" << total << "\nPercentage:" << perc;
        >

        int main()
        <
            student std[MAX];       //array of objects creation
            int n,loop;

            cout << "Enter total number of students: ";
            cin >> n;

            for(loop=0;loop< n; loop++){
                cout << "Enter details of student " << loop+1 << ":\n";
                std[loop].getDetails();
            >

            cout << endl;

            for(loop=0;loop< n; loop++){
                cout << "Details of student " << (loop+1) << ":\n";
                std[loop].putDetails();
            >

            return 0;
        >

That's getting there. The </> Code Block allows { and } so next time you create a discussion you can avoid character substitution.

OK, so there's your code. As you can guess this is some assignment so you get to write all the code. What's stopping you? What line is a problem?

I want the same code in python.

I guess something wasn't clear here. No one writes code for you unless it's some one liner or not much more.

Besides your first sentence is something you see in a homework assignment. https://docs.python.org/3/tutorial/classes.html tells me that yes you could create a class for that object so you have that going for you.

As to a Python version, that's your work unless you are putting it out there for pay.

Here is the python code of student management system. I'm not able to print any data after running the program.

class Student(object):

    def __init__(self, name, roll_number, mobile_number, email_id, section, subjects, obtained_marks, percentage):
            self.name = name
            self.roll_number = roll_number
            self.mobile_number = mobile_number
            self.email_id = email_id
            self.section = section
            self.subjects = subjects
            self.obtained_marks = obtained_marks
            self.percentage = percentage

            print("A student object is created.")

    def get_details(self):
       "Returns a string containing student's details."
       return "%s Student details %s" % (self.name, self.roll_number, self.mobile_number, self.email_id, self.section, self.subjects, self.obtained_marks)

    def print_details(self):
        """
        Prints the details of the student.
        """
        print("Name:", self.name)
        print("Roll Number:", self.roll_number)
        print("Mobile Number:", self.mobile_number)
        print("email-id:", self.email_id)
        print("Class of Student:", self.section)
        print("List of subjects:", self.subjects)
        print("Total marks out of 600:", self.obtained_marks)

        perc = obtained_marks/600*100
        percentage =(float)(perc)
        print("Percentage:", percentage)

Why would you expect any output? You've defined a class with methods but you haven't created any instances of that class. You code doesn't have any mainline section so nothing is being executed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.