Question

In: Computer Science

using correct c++ syntax, in one part write a short header file with only one constructor...

using correct c++ syntax, in one part write a short header file with only one constructor and one private variable. in another part write the function definition for the same constructor of the header file you just wrote.

using a correct c++ syntax, write only the top line of a derived header file that uses a base class. write the function definitions of two constructors in this derived class

Solutions

Expert Solution

Header File with only one private variable and constuctor :

Num.h

class Num
{
    //private variable
    private:
        int num;
        
    //constructor
    public:
        Num(int num);
        
}; 

another part has constructor definition of header file.

Num.cpp

#include <iostream>
#include "Num.h"
using namespace std;
       
//implementation of constuctor        
Num::Num(int n): num(n) 
{
    cout << "number : " << n << endl;
}

In another file, import a header file and call that constructors.

Main.cpp

#include "Num.h" 

int main()
{
    Num n1(35); 
    Num n2(15); 
    return 0;
}

OUTPUT :


Related Solutions

C++ constructor initializer list Constructor initializer list:         - syntax         - when it must be...
C++ constructor initializer list Constructor initializer list:         - syntax         - when it must be used         - how to instantiate and initialize data members that are user-defined types at the same time
Using C++, Write a class KeywordsInFile. Create KeywordsInFile.h and KeywordsInFile.cpp. The only required constructor for this...
Using C++, Write a class KeywordsInFile. Create KeywordsInFile.h and KeywordsInFile.cpp. The only required constructor for this class is KeywordsInFile( filename_with_keywords, filename_with_text) filename_with_keywords is a name of a plain text file that contains the list of keywords. For the future reference, the number of words in this file is denoted by N. filename_with_text is a name of a plain text file that contains the text where the keywords must be found. For the future reference, the number of words in this...
Write a C++ program that design a class definition to be put in a header file...
Write a C++ program that design a class definition to be put in a header file called fizzjazz.h A store sells online FizzJazz which are sound tones made by famous bands. For each FizzJazz, the store wants to keep track of the following attributes: * title - the name of the sound tone * band - Famous band name that created the tone * duration - this is in seconds and may be fractional: examples: 20.0, 34.5 Each attribute will...
Write a C++ program that design a class definition to be put in a header file...
Write a C++ program that design a class definition to be put in a header file called fizzjazz.h A store sells online FizzJazz which are sound tones made by famous bands. For each FizzJazz, the store wants to keep track of the following attributes: * title - the name of the sound tone * band - Famous band name that created the tone * duration - this is in seconds and may be fractional: examples: 20.0, 34.5 Each attribute will...
Write a C++ program that design a class definition to be put in a header file...
Write a C++ program that design a class definition to be put in a header file called fizzjazz.h A store sells online FizzJazz which are sound tones made by famous bands. For each FizzJazz, the store wants to keep track of the following attributes: * title - the name of the sound tone * band - Famous band name that created the tone * duration - this is in seconds and may be fractional: examples: 20.0, 34.5 Each attribute will...
Can someone please write me a header file in c++ using the quadratic probing hash method...
Can someone please write me a header file in c++ using the quadratic probing hash method that will work with this program? #include "hash.h" #include <algorithm> #include <cstdlib> #include <ctime> #include <iostream> #include <list> using namespace std; const size_t KEYS_COUNT = 1000; // Number of keys to generate for testing string random_key(); class HashCheck { private: size_t count; Hash hash; public: HashCheck(Hash& h) { count = 0; hash = h; } void operator() (const string key) { if (hash[key] !=...
Please Write Code in C++ and include the correct #include <header> and not a catchall such...
Please Write Code in C++ and include the correct #include <header> and not a catchall such as bits/stdc: Write a recursive, string-valued function, replace, that accepts a string and returns a new string consisting of the original string with each blank replaced with an asterisk (*) Replacing the blanks in a string involves: Nothing if the string is empty Otherwise: If the first character is not a blank, simply concatenate it with the result of replacing the rest of the...
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:...
using the header: #include <pthread.h> // This is a header file for a Read/Right Lock Library....
using the header: #include <pthread.h> // This is a header file for a Read/Right Lock Library. Your C code //SHOULD access your routines using these exact function // prototypes typedef struct RW_lock_s { } RW_lock_t; void RW_lock_init(RW_lock_t *lock); /* This routine should be called on a pointer to a struct variable of RW_lock_t to initialize it and ready it for use. */ void RW_read_lock(RW_lock_t *lock); /* This routine should be called at the beginning of a READER critical section */...
C++ Programming Simply explain what the difference between "including" a header file and using a compiled...
C++ Programming Simply explain what the difference between "including" a header file and using a compiled library file during linking? Where are the C++ header files and compiled C++ library files on your computer?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT