Design and implement a C++ project of moderate size, consisting
of a main driver file and multiple files.
Use the “make” utility, a software engineering tool for managing
and maintaining computer programs.
Use the UNIX command line interface to spawn processes
that redirect output or communicate through a pipe.
Demonstrate knowledge of variable scope rules by
predicting program output (i.e. testing your code since it will
contain lots of scopes).
Process command line argument flags in any order
Decomposing a complicated problem into simpler parts
Exhaustive search is a problem that is often encountered in
computer science and many other disciplines. Exhaustive search
involves having a program consider all possible ways of solving a
problem to find a set of solutions. In this project, you will write
a program that will exhaustively search all possible expressions
(under the constraints mentioned later in this document) to print
out all expressions that evaluate to a certain value based on
command line inputs.
Your program must process command line arguments with flags:
“-a” for using a specific set of arithmetic operators or “-b” for
using a specific set of bitwise operator, “-e” follow by a single
integer, and “-v” followed by 5 integer values where each integer
is different (no repeats) and greater than 0. The flags can be in
any order, but you may assume the following about the input (which
is similar to many Linux/Unix commands).
Only “-a” or “-b” (not both) will be used for input (this means
your program will only consider arithmetic or bitwise operations
(not both) during a single run of your program).
The argument after “-e” will be an integer (use type int).
The next 5 arguments after “-v” will be valid integers (use type
int) as aforementioned.
Given the set of arithmetic operator A = {+, -, *, /, % },
bitwise operators B = {<<, >>, &, |, ^}, input set
of 5 integer values V (arguments following the -v flag), and input
integer e, print all expressions involving all 5 values of V and 4
operators from either A or B (not both) that evaluate to e using
following the rules.
Each expression must contain all 5 values of V without any
repeated operands.
The 4 operators used in each expression can contain repeated
operators, and we are only using the binary operators (operators
that use two operands).
Each expression must be parenthesized as shown in the
examples.
Each expression is evaluated based on C and C++ rules using the
type int for all integer values.
Study the examples in the Examples section to understand the
problem before you start to code. After printing all expressions,
your program should print the total number (as shown in the
examples). Your program’s I/O must match the examples given in the
Examples section. Also note that a few examples with many lines of
output use the ‘>’ symbol to redirect output to a file (output
file(s) are on eLC) and ‘|’ symbol to pipe output to command(s) on
odin. Also note that the redirect output and pipe are not passed as
command line arguments to your main function by the operating
system. When you test out your program, experiment with piping and
redirecting output to a file
Your program must handle command line arguments as shown in the
Examples section, and your I/O must be exactly like the examples
shown.
Your program must run to completion in less than 10 seconds on
odin. If your program runs longer than 10 seconds, then use the
Unix kill command to end the program (look up the kill command if
you don’t know how to use it).
Your program must compile with all targets, dependencies, and
commands given in the Makefile, which is on eLC for this project.
This means that you must download, read, understand, and use the
Makefile. You CANNOT modify the provided Makefile, which means
you’ll need to split your program into multiple files (proj1.h,
main.cpp, proj1.cpp), and details about these files are below.
(a) proj1.h must contain all of your prototypes (and other
information as needed)
(b) main.cpp must contain the main function that processes
command line arguments and passes these arguments to one function
found in proj1.cpp. The main function cannot do more than process
command line arguments and pass them to one function in proj1.cpp,
the main function must be the only function in this file, and the
main function’s source code cannot exceed 30 lines of code (this
does not include comments). Otherwise, points will be deducted for
poor programming style.
(c) proj1.cpp contains all other functions necessary to
complete this project.
(d) All functions should be commented properly.
(e) You cannot use a break, continue, or goto statement
for this project. If your source code contains one or more break,
continue, or goto statment(s), then you will receive a zero for
this assignment.
Examples
2
The only include directives that you are authorized to use in
your source code for this assignment are listed below.
You cannot use any other include directives anywhere in your
source code. Using an unauthorized include directive anywhere in
your source code may result in a grade of zero on this
assignment.
- makefile-
CC = g++
DEBUG = -g
CFLAGS = -Wall -c -pedantic-errors $(DEBUG)
LFLAGS = -Wall $(DEBUG)
compile: proj1.out
proj1.out: main.o proj1.o
$(CC) $(LFLAGS) -o proj1.out main.o proj1.o
main.o: main.cpp proj1.h
$(CC) $(CFLAGS) main.cpp
proj1.o: proj1.cpp proj1.h
$(CC) $(CFLAGS) proj1.cpp
run: proj1.out
./proj1.out -a -v 5 2 3 1 9 -e 97 | sort -n
./proj1.out -v 5 2 3 1 9 -e 97 -a | sort -n
./proj1.out -e 97 -v 5 2 3 1 9 -b | sort -n
./proj1.out -v 5 2 3 1 9 -b -e 97 | sort -n
clean:
rm proj1.out
rm *.o
// c++ language full code please.
Design and implement a C++ project of moderate size, consisting of a main driver file and multiple files. Use the “make”
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am