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

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:...
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...
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...
I am Writing a C-Program to read and write files. but none of my code is...
I am Writing a C-Program to read and write files. but none of my code is working like it should be. Please fix all code and supply output response. Please try to use existing code and code in comments. But if needed change any code that needs to be changed. Thank you in advance //agelink.c //maintains list of agents //uses linked list #include <stdio.h> #include <stdlib.h> #define TRUE 1 void listall(void); void newname(void); void rfile(void); void wfile(void); struct personnel {...
Complete the following task in C++. Separate your class into header and cpp files. You can...
Complete the following task in C++. Separate your class into header and cpp files. You can only useiostream, string and sstream. Create a main.cpp file to test your code thoroughly. Given : commodity.h and commodity.cpp here -> https://www.chegg.com/homework-help/questions-and-answers/31-commodity-request-presented-two-diagrams-depicting-commodity-request-classes-form-basic-q39578118?trackid=uF_YZqoK Create : locomotive.h, locomotive.cpp, main.cpp Locomotive Class Hierarchy Presented here will be a class diagram depicting the nature of the class hierarchy formed between a parent locomotive class and its children, the two kinds of specic trains operated. The relationship is a...
Complete the following task in C++. Separate your class into header and cpp files. You can...
Complete the following task in C++. Separate your class into header and cpp files. You can only use iostream, string and sstream. Create a main.cpp file to test your code thoroughly. Given : commodity.h and commodity.cpp here -> https://www.chegg.com/homework-help/questions-and-answers/31-commodity-request-presented-two-diagrams-depicting-commodity-request-classes-form-basic-q39578118?trackid=uF_YZqoK Given : locomotive.h, locomotive.cpp, main.cpp -> https://www.chegg.com/homework-help/questions-and-answers/complete-following-task-c--separate-class-header-cpp-files-useiostream-string-sstream-crea-q39733428 Create : DieselElectric.cpp DieselElectric.h DieselElectric dieselElectric -fuelSupply:int --------------------------- +getSupply():int +setSupply(s:int):void +dieselElectric(f:int) +~dieselElectric() +generateID():string +calculateRange():double The class variables are as follows: fuelSuppply: The fuel supply of the train in terms of a number of kilolitres...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT