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...
Programming Language: C++ Overview For this assignment, write a program that will simulate a single game...
Programming Language: C++ Overview For this assignment, write a program that will simulate a single game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice is equal to 7 or 11, the player wins immediately....
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...
Programming Assignment #2, Processes Write a C program (time_shm.c) that determines the amount of time necessary...
Programming Assignment #2, Processes Write a C program (time_shm.c) that determines the amount of time necessary to run a command from the command line. This program will be run as ./time <command [args...]> and will report the amount of elapsed time to run the specified command. This will involve using fork() and execvp() functions, as well as the gettimeofday() function to determine the elapsed time. It will also require the use of two different IPC mechanisms. The general strategy is...
[ 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]
Write a program in c++ to do the following : (1) Declare an array a of...
Write a program in c++ to do the following : (1) Declare an array a of size 10 and three pointer variables p, q, and v. (2) Write a loop to fill array a with values 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 (3) write following statement: p= &a[2]; q = &a[5]; i = *q - *p; cout<<“The value of i is”<< i; i = *p - *q; cout<<“The value of i is %d”<< i; 4) assign...
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...
introduction: C PROGRAMMING For this assignment you will write an encoder and a decoder for a...
introduction: C PROGRAMMING For this assignment you will write an encoder and a decoder for a modified "book cipher." A book cipher uses a document or book as the cipher key, and the cipher itself uses numbers that reference the words within the text. For example, one of the Beale ciphers used an edition of The Declaration of Independence as the cipher key. The cipher you will write will use a pair of numbers corresponding to each letter in the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT