help me please

#include <iostream>
#include <string>
using namespace std;

class students
{
int data_members;
public:
string first_name;
string last_name;
double gpa;
};



int main()
{
students obj;
cout<<"Enter first name: ";
cin>> obj.first_name;
cout<<"Enter last name: ";
cin>> obj.last_name;
cout<<"Gpa: ";
cin>> obj.gpa;
if (obj.gpa <0)
{
cout<< "0";
}
cout<< obj.first_name <<","<< obj.last_name<< "," <<obj.gpa<<endl;
}


Create a class called Student that includes three pieces of information as data members—a first name (type string), a last name (type string) and a GPA (type double).
Your class should have a constructor that initializes the three data members. Provide a set and a get function for each data member. If the GPA is not positive, set it to 0. Write a test program that demonstrates class Student’s capabilities. Create two Student objects and display each object’s CGPA. Then give each Student a 10 percent raise and display each Student’s CGPA again.
closed account (E0p9LyTq)
Your class declaration could be something more like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Student
{
public:
   Student(std::string f_name, std::string l_name, double grade);
   ~Student() {}
   
public:
   std::string GetFirstName() const;
   void SetFirstName(std::string f_name);
   // the rest of the getters and setters are up to you

private:
   std::string first_name;
   std::string last_name;
   double GPA;
};


Now go and pump some neurons finishing the code.
@OP: The code you've given does nothing to address the problem you've posted. In order to accomplish anything in programming, you must break down your whole task into smaller subtasks that you can accomplish one at a time.

Start with the most bare-bones program in the world.
1
2
3
int main()
{
}


This code should compile. When you run it, it should do nothing.

Break your task into smaller tasks. Implement them one at a time. At the end of each subtask you should have code that compiles and runs.
-Create a class called Student
1
2
3
4
5
6
7
class Student
{
};

int main()
{
}


-Include three pieces of information as data members
*first name (type string)
*last name (type string)
*GPA (type double)
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <string>

class Student
{
private:
    std::string firstName;
    std::string lastName;
    double gpa;
};

int main()
{
}

The rest of your task could be broken down like this:
-Add constructor
-Make constructor initialize the data members
-Provide a set and get function for firstName
-Provide a set and get function for lastName
-Provide a set and get function for gpa
-Update GPA's set function to set gpa=0 if the parameter passed in is negative


-Write a test program that demonstrates class Student's capabilities (this stuff will go inside the body of the main function) *Create two Student objects
*Display each object's GPA (hint: use cout and getGpa function from a few steps ago)
*use getGpa to get the student's GPA, multiply it by 1.1, use setGpa and pass it the new value
Last edited on
Topic archived. No new replies allowed.