Question

In: Computer Science

i need an example of a program that uses muliple .h and .cpp files in c++...

i need an example of a program that uses muliple .h and .cpp files in c++ if possible.

Solutions

Expert Solution

Short Summary:

  • Provided the source code and sample output as per the requirements.

**************Please upvote the answer and appreciate our time.************

Source Code:

Date.h:

#ifndef DATE_H
#define DATE_H
class Date{
public:
Date(int m,int d,int y);
void display();
private:
int month;
int day;
int year;
};
#endif

Date.cpp:

#include "Date.h"
#include <iostream>

using namespace std;
Date :: Date(int m,int d, int y):month(m),day(d),year(y){
}

void Date :: display(){
cout << month << '/' << day << '/' << year << endl;
}

Time.h:

#ifndef TIME_H
#define TIME_H
class Time{
public:
Time(int h,int m);
void display();
private:
int hour;
int minute;
};
#endif

Time.cpp:

#include "Time.h"
#include <iostream>
#include <iomanip>
using namespace std;
Time :: Time(int h,int m):hour(h),minute(m){
}

void Time :: display(){
cout << hour << ':' << setw(2) << setfill('0') << minute << endl;
setfill(' ');
}

Report.h:

#ifndef REPORT_H
#define REPORT_H
#include "Date.h"
#include "Time.h"
#include <iostream>
#include <string>
using namespace std;

// Report class
class Report{
public:
// six argument constructor
Report(int month,int day,int year,int hour,int minute,string description);
// display the report
void display();
private:
// attributes of Report
string rep_desc;
Date rep_date;
Time rep_time;
};
#endif

Report.cpp:

#include "Report.h"
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

// six constructor argument
Report :: Report(int month,int day,int year,int hour,int minute,string description):
rep_date(month,day,year),rep_time(hour, minute),rep_desc(description){

}

// display method of report
void Report :: display(){
cout << "Report date: ";
// calling the date display method
rep_date.display();
cout << "Report time: ";
// calling the time display method
rep_time.display();
// display the description of Report
cout << "Report desc: " << rep_desc << endl;
}

main.cpp:

#include "Date.h"
#include "Time.h"
#include "Report.h"
#include <iostream>

using namespace std;

int main()
{
Report r(7,4,1776,10,15,"Test Data");
r.display();

return 0;
}

Sample Run:

**************************************************************************************

Feel free to rate the answer and comment your questions, if you have any.

Please upvote the answer and appreciate our time.

Happy Studying!!!

****************************************************************************************


Related Solutions

Separate code into .cpp and .h files: // C++ program to create and implement Poly class...
Separate code into .cpp and .h files: // C++ program to create and implement Poly class representing Polynomials #include <iostream> #include <cmath> using namespace std; class Poly { private: int degree; int *coefficients; public: Poly(); Poly(int coeff, int degree); Poly(int coeff); Poly(const Poly& p); ~Poly(); void resize(int new_degree); void setCoefficient(int exp, int coeff); int getCoefficient(int exp); void display(); }; // default constructor to create a polynomial with constant 0 Poly::Poly() { // set degree to 0 degree = 0; //...
Write C++ program (submit the .cpp,.h, .sln and .vcxproj files) Problem 1. Generate 100 random numbers...
Write C++ program (submit the .cpp,.h, .sln and .vcxproj files) Problem 1. Generate 100 random numbers of the values 1-20 in an input.txt. Now create a binary search tree using the numbers of the sequence. The tree set should not have any nodes with same values and all repeated numbers of the random sequence must be stored in the node as a counter variable. For example, if there are five 20s’ in the random sequence then the tree node having...
WRITE ONLY THE TO DO'S   in FINAL program IN C++ (necessary cpp and header files are...
WRITE ONLY THE TO DO'S   in FINAL program IN C++ (necessary cpp and header files are witten below) "KINGSOM.h " program below: #ifndef WESTEROS_kINGDOM_H_INCLUDED #define WESTEROS_KINGDOM_H_INCLUDED #include <iostream> namespace westeros { class Kingdom{         public:                 char m_name[32];                 int m_population; };         void display(Kingdom&);                      } #endif } Kingdom.cpp Program below: #include <iostream> #include "kingdom.h" using namespace std; namespace westeros {         void display(Kingdom& pKingdom) {                 cout << pKingdom.m_name << ", population " << pKingdom.m_population << endl;                                                               FINAL:...
In C++ You will create 3 files: The .h (specification file), .cpp (implementation file) and main...
In C++ You will create 3 files: The .h (specification file), .cpp (implementation file) and main file. You will practice writing class constants, using data files. You will add methods public and private to your BankAccount class, as well as helper methods in your main class. You will create an arrayy of objects and practice passing objects to and return objects from functions. String functions practice has also been included. You have been given a template in Zylabs to help...
Write the header and the implementation files (.h and .cpp separatelu) for a class called Course,...
Write the header and the implementation files (.h and .cpp separatelu) for a class called Course, and a simple program to test it, according to the following specifications:                    Your class has 3 member data: an integer pointer that will be used to create a dynamic variable to represent the number of students, an integer pointer that will be used to create a dynamic array representing students’ ids, and a double pointer that will be used to create a dynamic array...
Write the header and the implementation files (.h and .cpp separately) for a class called Course,...
Write the header and the implementation files (.h and .cpp separately) for a class called Course, and a simple program to test it (C++), according to the following specifications:                    Your class has 3 member data: an integer pointer that will be used to create a dynamic variable to represent the number of students, an integer pointer that will be used to create a dynamic array representing students’ ids, and a double pointer that will be used to create a dynamic...
C++ question. Need all cpp and header files. Part 1 - Polymorphism problem 3-1 You are...
C++ question. Need all cpp and header files. Part 1 - Polymorphism problem 3-1 You are going to build a C++ program which runs a single game of Rock, Paper, Scissors. Two players (a human player and a computer player) will compete and individually choose Rock, Paper, or Scissors. They will then simultaneously declare their choices and the winner is determined by comparing the players’ choices. Rock beats Scissors. Scissors beats Paper. Paper beats Rock. The learning objectives of this...
C++ Program Create Semester class (.h and .cpp file) with the following three member variables: ▪...
C++ Program Create Semester class (.h and .cpp file) with the following three member variables: ▪ a semester name (Ex: Fall 2020) ▪ a Date instance for the start date of the semester ▪ a Date instance for the end date of the semester The Semester class should have the following member functions 1. Create a constructor that accepts three arguments: the semester name, the start Date, and the end Date. Use default values for all the parameters in the...
Files I need to be edited: I wrote these files and I put them in a...
Files I need to be edited: I wrote these files and I put them in a folder labeled Project 7. I am using this as a study tool for a personal project of mine. //main.cpp #include <iostream> #include "staticarray.h" using namespace std; int main( ) {    StaticArray a;    cout << "Printing empty array -- next line should be blank\n";    a.print();    /*    // Loop to append 100 through 110 to a and check return value    // Should print "Couldn't append 110"...
How do you use header files on a program? I need to separate my program into...
How do you use header files on a program? I need to separate my program into header files/need to use header files for this program.Their needs to be 2-3 files one of which is the menu. thanks! #include #include #include using namespace std; const int maxrecs = 5; struct Teletype { string name; string phoneNo; Teletype *nextaddr; }; void display(Teletype *); void populate(Teletype *); void modify(Teletype *head, string name); void insertAtMid(Teletype *, string, string); void deleteAtMid(Teletype *, string); int find(Teletype...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT