Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA CODE ONLY! ________________ C++ code is divided into two different file typ

ID: 3833105 • Letter: J

Question

JAVA CODE ONLY!

________________

C++ code is divided into two different file types. Header file which holds class and functions deceleration. Header files usually have the following extensions, .h, .hpp, and .hxx. Source file which holds the actual definition of class and functions. Source files usually have the following extensions, .C, .cpp, and .cxx.

One of the difficulties that C++ programmers have is include file pollution. This means that a Source file and/or Header file includes same Header file or one Header file is included multiple times by other Header files.

For example:

myProject1/
- Class1.hpp - Class1.cpp - Class2.hpp - Class2.cpp - Main.cpp

Class2.hpp includes Class1.hpp
Main.cpp includes Class1.hpp and Class2.hpp

Hint: You can use java.util.regex. in your code.

Your task is to create an application which searches through all Source and Header files in another project and outputs all files that have Header file pollution.

For example, (Running program on above example, myProject1):

java code_analysis –i /data/projects/myProject1

Class1.hpp is included twice in Main.cpp. Remove Class1.hpp from one of the files below: 1. Class2.hpp includes Class1.hpp
2. Main.cpp includes Class1.hpp

myProject1/
- Class1.hpp - Class1.cpp - Class2.hpp - Class2.cpp - Main.cpp

Class2.hpp includes Class1.hpp
Main.cpp includes Class1.hpp and Class2.hpp

Explanation / Answer

The standard and the compiler don't generally think much about whether a record is .cpp or .h or .monkeyface. The ideas driving organizing your source code into usage and header records are truly quite recently acknowledged approaches to help deal with your source. In spite of this, not organizing your source in the acknowledged way is regularly thought to be off base or terrible C++.
All #include does is advise the preprocessor to incorporate the substance of the record you indicate in the present document. It resembles duplicating and gluing the other record into yours. When you say #include "foo.h", it just incorporates the substance of foo.h and couldn't care less about foo.cpp by any means - it doesn't realize that it exists (and there's no reason it needs to exist).
Organizing your source code in execution and header records is to a great degree valuable - it maintains a strategic distance from issues with conditions and various definitions, and furthermore enhances assemblage time fairly. At the point when your code utilizes another class, you just need to #include the header petition for that class. The reason is on account of your code doesn't have to think about the execution of the class, it simply has to comprehend what it would seem that (its name, individuals, base class, and so on.). It doesn't fret about how precisely the part capacities are executed.
The expansions .cpp and .h are only traditions. A few people like to utilize .hpp for header records. A few people even utilize .tpp for layout executions. You can name them anyway you like - yes, you can even incorporate a .txt record. Your compiler most likely tries to gather things about records (for instance, which dialect to assemble it as) from the document augmentation, however that is typically overrideable.
So if your main.cpp incorporates foo.h in light of the fact that it utilizes class foo, when does foo.cpp get included? All things considered, in the aggregation of main.cpp, it doesn't get included by any stretch of the imagination. main.cpp doesn't have to think about the execution of the class, as we talked about above. Nonetheless, when accumulating your whole program, you will pass each of your .cpp records to the compiler to be incorporated independently. That is, you would accomplish something like g++ main.cpp foo.cpp. At the point when foo.cpp is gathered, it will incorporate the headers that it needs to arrange.