Question

In: Computer Science

Programming assignment 4 : C++ Write a program to do the following: 1.Define a structure to...

Programming assignment 4 : C++

Write a program to do the following:

1.Define a structure to store a date, which includes day(int), month(int), and year(int).

2.Define a structure to store an address, which includes address(house number and street)(string), city(string), state(string), zip code (string).

3.Define a class to store the following information about a student. It should include private member variables: name(string), ID (int), date of birth (the first structure), address (the second structure), total credit earned (int), and GPA (double). And it also has public member functions: constructors(at least one default and one non-default), Accessors and Mutators for each member variable, and so on.(write definitions of at least one member function outside the class).

4.Test each member function of the class in main function. Each piece information of a student is inputted by user, not initialized by you (programmer)except for default constructor.5.In main function, choose any one student you defined,and then check whether the student lives in the zip code of 11235 (close to school)or not,and check whether the student’s birthday is in November or not.

Solutions

Expert Solution

CODE:

#include <iostream>

#include <string>

using namespace std;

struct date  //structure to store a date

{

    int day;

    int month;

    int year;

};

struct address //structure to store an address

{

    string house_street;

    string city;

    string state;

    string zip_code;

};

class Student //class student to store student details

{

    string name;

    int id;

    struct date dob;

    struct address address;

    int totalCreditEarned;

    double GPA;

public:

    Student(string n, int i = -1) //constructor

    {

        name = n;

        id = i;

    }

    //all getter setter methods prototypes

    void setName(string n);

    void setId(int i);

    void setDate(int d, int m, int y);

    void setAddress(string h, string c, string s, string z);

    void setTotalCreditEarned(int t);

    void setGPA(double g);

    string getName();

    int getId();

    struct date getDate();

    struct address getAddress();

    int getTotalCreditEarned();

    double getGPA();

};

//all the function definitions declared in the class Student

void Student::setName(string n)

{

    name = n;

}

void Student::setId(int i)

{

    id = i;

}

void Student::setDate(int d, int m, int y)

{

    dob.day = d;

    dob.month = m;

    dob.year = y;

}

void Student::setAddress(string h, string c, string s, string z)

{

    address.house_street = h;

    address.city = c;

    address.state = s;

    address.zip_code = z;

}

void Student::setTotalCreditEarned(int t)

{

    totalCreditEarned = t;

}

void Student::setGPA(double g)

{

    GPA = g;

}

string Student::getName()

{

    return name;

}

int Student::getId()

{

    return id;

}

struct date Student::getDate()

{

    return dob;

}

struct address Student::getAddress()

{

    return address;

}

int Student::getTotalCreditEarned()

{

    return totalCreditEarned;

}

double Student::getGPA()

{

    return GPA;

}

int main()

{

    Student student("Raven"); //object with the name Raven

    string h, c, s, z;

    int d, m, y;

    int id;

    int credit;

    double gpa;

    char temp;

    cout << "\nEnter the ID: "; //entering ID

    cin >> id;

    cout << "\nEnter the Birthday: "; //Entering birthday

    cout << "\n\tDay: ";

    cin >> d;

    cout << "\tMonth: ";

    cin >> m;

    cout << "\tYear: ";

    cin >> y;

    getchar(); //since next value input is a char, it will also take in the char value of the enter key from the previous input

    cout << "\nEnter the Address: ";

    cout << "\n\tHouse & Street: ";

    getline(cin, h); //reading string as home and steeet

    cout << "\tCity: ";

    getline(cin, c); //reading string for city

    cout << "\tState: ";

    getline(cin, s); //reading string for state

    cout << "\tZip Code: "; //reading string for zip

    getline(cin, z);

    cout << "\nEnter the Total Credits Earned: "; //getting total credits earned

    cin >> credit;

    cout << "\nEnter the GPA: "; //entering gpa

    cin >> gpa;

    //we will set all the values here to the object

    student.setId(id);

    student.setDate(d, m, y);

    student.setAddress(h, c, s, z);

    student.setTotalCreditEarned(credit);

    student.setGPA(gpa);

    cout << "\n------------------------------------------------------------\n";

    if (student.getAddress().zip_code == "11235") //checking if the struct address's zip code is 11235

    {

        cout << "\nYes! The student " << student.getName() << "'s ZIP CODE IS 11235";

    }

    else

    {

        cout << "\nNo! The student " << student.getName() << "'s ZIP CODE IS NOT 11235";

    }

    if (student.getDate().month == 11) //checking if the struct date's month value is 11

    {

        cout << "\nYes! The student " << student.getName() << "'s BIRTH MONTH IS NOVEMBER";

    }

    else

    {

        cout << "\nNo! The student " << student.getName() << "'s BIRTH MONTH IS NOT NOVEMBER";

    }

    cout << endl

         << endl;

}

OUTPUT:


Related Solutions

C PROGRAMMING – Steganography In this assignment, you will write an C program that includes processing...
C PROGRAMMING – Steganography In this assignment, you will write an C program that includes processing input, using control structures, and bitwise operations. The input for your program will be a text file containing a large amount of English. Your program must extract the “secret message” from the input file. The message is hidden inside the file using the following scheme. The message is hidden in binary notation, as a sequence of 0’s and 1’s. Each block of 8-bits is...
write pseudocode not c program If- else programming exercises 1.    Write a C program to find...
write pseudocode not c program If- else programming exercises 1.    Write a C program to find maximum between two numbers. 2.    Write a C program to find maximum between three numbers. 3.    Write a C program to check whether a number is negative, positive or zero. 4.    Write a C program to check whether a number is divisible by 5 and 11 or not. 5.    Write a C program to check whether a number is even or odd. 6.    Write...
1. INTRODUCTION The goal of this programming assignment is for students to write a Python program...
1. INTRODUCTION The goal of this programming assignment is for students to write a Python program that uses repetition (i.e. “loops”) and decision structures to solve a problem. 2. PROBLEM DEFINITION  Write a Python program that performs simple math operations. It will present the user with a menu and prompt the user for an option to be selected, such as: (1) addition (2) subtraction (3) multiplication (4) division (5) quit Please select an option (1 – 5) from the...
Programming II: C++ - Programming Assignment Vector Overloads Overview In this assignment, the student will write...
Programming II: C++ - Programming Assignment Vector Overloads Overview In this assignment, the student will write a C++ program that overloads the arithmetic operators for a pre-defined Vector object. When completing this assignment, the student should demonstrate mastery of the following concepts: · Object-oriented Paradigm · Operator Overloading - Internal · Operator Overloading - External · Mathematical Modeling Assignment In this assignment, the student will implement the overloaded operators on a pre-defined object that represents a Vector. Use the following...
[ Write in C not C++] 1. Define a C structure Covid19Info to store the information...
[ Write in C not C++] 1. Define a C structure Covid19Info to store the information of COVID 19 cases of countries around the world. It keeps the name of the country, number of COVID 19 cases, number of deaths, current test positive rate, etc. After defining the structure, declare a variable of Covid19Info type with some initial values for Bangladesh. [8]
This programming assignment will consist of a C++ program. Your program must compile correctly and produce...
This programming assignment will consist of a C++ program. Your program must compile correctly and produce the specified output. Please note that your programs should comply with the commenting and formatting described in the Required Program Development Best Practices document that has been discussed in class and is posted to the eLearning system. Please see this descriptive file on the eLearning system for more details. The name to use in the main configuration screen text box Name: [ ] in...
Lab 1 Write a program in the C/C++ programming language to input and add two fractions...
Lab 1 Write a program in the C/C++ programming language to input and add two fractions each represented as a numerator and denominator. Do not use classes or structures. Print your result (which is also represented as a numerator/denominator) to standard out. If you get done early, try to simplify your result with the least common denominator. The following equation can be used to add fractions: a/b + c/d = (a*d + b*c)/(b*d) Example: 1/2 + 1/4 = ( 1(4)...
The assignment: C++ program or Java You need to use the following programming constructs/data structures on...
The assignment: C++ program or Java You need to use the following programming constructs/data structures on this assignment. 1. A structure named student which contains:   a. int ID; student id; b. last name; // as either array of char or a string c. double GPA;    2. An input file containing the information of at least 10 students. 3. An array of struct: read the student information from the input file into the array. 4. A stack: you can use the...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user to enter the name of the month he/she was born in (example: September). b) Prompt the user to enter his/her weight in pounds (example: 145.75). c) Prompt the user to enter his/her height in feet (example: 6.5). d) Display (print) a line of message on the screen that reads as follows: You were born in the month of September and weigh 145.75 lbs. and...
Programming in C++ Write a program that prints the values in an array and the addresses...
Programming in C++ Write a program that prints the values in an array and the addresses of the array’s elements using four different techniques, as follows: Array index notation using array name Pointer/offset notation using array name Array index notation using a pointer Pointer/offset notation using a pointer Learning Objectives In this assignment, you will: Use functions with array and pointer arguments Use indexing and offset notations to access arrays Requirements Your code must use these eight functions, using these...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT