TASK 1

Your first task is to create a Makefile for a project. A project has been provided to you in the compressed file CSCI124-Lab3.zip. In this file you will find numerous headers and source files. You can ignore the fact the program is implemented using classes. The program once compiled takes a source file name and prints out the symbols in the file and line numbers they appear on. The function is largely irrelevant to the task at hand.

The program can be compiled easily by using:

$ g++ *.cp

That said this is not desirable. Your job is to create a Makefile, called makefile.txt which builds all the targets associated with the project and links them together to build the executable foobar. To do this you will need to review the files and understand the dependencies.

Your makefile should have a clean target to remove all objects and executables.

Place your solution in the file makefile.txt.

TASK 2

Your second task is to write a program, which does some pattern matching. Pattern matching is commonly used when we want to identify something in a file.

Your mission is to write a C++ program which can find header dependencies in C++ source files i.e. .cpp files.

An include can be of any of the following forms:

include <iostream>
#include <iostream>
include <iostream>
include <iostream>
include “myheader.h”
#include “myheader.h
include “myheader.h”
include     “myheader.h”
include directives indicate header file inclusion. The #include directive can appear on any line in a source file (or even within a header) and it need not begin on the first character of a line (there can be as much leading white space e.g. tabs and whitespace). As indicated above you can only have one #include per line but it may be proceeded by code or even comments, which can be ignored till the end of line.

Between the #include there can be any number of white space characters (including tabs etc) followed by either a < or “. Within the < or “ there is a string which is known as the dependency – such strings may have white spaces in them. The header string is typically followed by a closing > or “.

Your job is to write a program which prompts the user for a C++ source file and prints out all the dependencies. A C++ source file ends with a .cpp extension. If this is not met print an error and terminate.

A sample run of the program using the main.cpp from csci124-lab3.zip should yield the following:

Enter Filename: main.cpp

Dependencies:

iostream
program.h
binarytree.h

Where includes do not meet the above specified form, exclude it from the summary list. You only need to look for includes in the source file specified. You can assume there will only ever be one include per line.

Place your code to solve this problem into the file depend.cpp and depend.h. Write a suitable driver function and place it in main.cpp.

So, this is the output for task 1 , i not sure whether its correct anot , i wrote all them create .o object file in a text file(.txt).

Identifier: binarytree
Line Numbers: 1 2 4 7 8

Identifier: c
Line Numbers: 5 8 11 14

Identifier: cpp
Line Numbers: 1 2 4 5 7 8 10 11 13 14

Identifier: g
Line Numbers: 2 5 8 11 14

Identifier: h
Line Numbers: 4 7 10 13

Identifier: linkedlist
Line Numbers: 1 2 4 10 11

Identifier: list
Line Numbers: 1 2 4 13 14

Identifier: main
Line Numbers: 1 2 4 5

Identifier: o
Line Numbers: 2 4 7 10 13

Identifier: prog
Line Numbers: 1 2

Identifier: program
Line Numbers: 1 2 4 13 14

Now , if task 1 is correct , what should i proceed with task 2?
Please give some idea ~ i nid to submit these in 2 day..

Recommended Answers

All 8 Replies

what is the question???

TASK 2

Your second task is to write a program, which does some pattern matching. Pattern matching is commonly used when we want to identify something in a file.

Your mission is to write a C++ program which can find header dependencies in C++ source files i.e. .cpp files.

An include can be of any of the following forms:

include <iostream>

include <iostream>

include <iostream>
include <iostream>
include “myheader.h”

include “myheader.h

include “myheader.h”

Header

include directives indicate header file inclusion. The #include directive can appear on any line in a source file (or even within a header) and it need not begin on the first character of a line (there can be as much leading white space e.g. tabs and whitespace). As indicated above you can only have one #include per line but it may be proceeded by code or even comments, which can be ignored till the end of line.
Between the #include there can be any number of white space characters (including tabs etc) followed by either a < or “. Within the < or “ there is a string which is known as the dependency – such strings may have white spaces in them. The header string is typically followed by a closing > or “.

Your job is to write a program which prompts the user for a C++ source file and prints out all the dependencies. A C++ source file ends with a .cpp extension. If this is not met print an error and terminate.

A sample run of the program using the main.cpp from csci124-lab3.zip should yield the following:

Enter Filename: main.cpp

Dependencies:

iostream
program.h
binarytree.h

Where includes do not meet the above specified form, exclude it from the summary list. You only need to look for includes in the source file specified. You can assume there will only ever be one include per line.

Place your code to solve this problem into the file depend.cpp and depend.h. Write a suitable driver function and place it in main.cpp.

This is my problem , what can i do to achieve what the task 2 wants?

And i am given all of the cpp files header files but i need to create the object file myself as mentioned in task 1, then i need to proceed with task 2 by finding the file dependencies. Help ~

Well, no one is going to do your homework for you. You have explained the assignment, which part(s) don't you understand?

Erm, The task 2 is the part i dont understand, i just need some idea what to start with? i should read the file , then set it to a temporary variable, and use a for loop to check for the < and " , if is found, then wat to do?

Well if you can use the string classs the you can use the find() method to look for the word include. Then parse from there to make sure it is correct.

Our lecturer does not allow us to use string btw, only char array is allowed

Well you can use strstr() from the cstring library. That will work with char arrays.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.