read the assignment before contact with me
makefile.txt
DIR=${PWD} ASST=$(notdir ${DIR}) MAINPROG=pdriver ifneq (,$(findstring MinGW,$(PATH))) DISTR=MinGW EXE=.exe LFLAGS= else DISTR=Unix EXE= LFLAGS= endif # ######################################################################## # Macro definitions for "standard" C and C++ compilations # CPPFLAGS=-g -D$(DISTR) CFLAGS=-g TARGET=$(MAINPROG)$(EXE) CPPS=pdriver.cpp permute.cpp LINK=g++ $(CPPFLAGS) # CC=gcc CXX=g++ # # # In most cases, you should not change anything below this line. # # The following is "boilerplate" to set up the standard compilation # commands: # OBJS=$(CPPS:%.cpp=%.o) DEPENDENCIES = $(CPPS:%.cpp=%.d) %.d: %.cpp touch $@ %.o: %.cpp $(CXX) $(CPPFLAGS) -MMD -o $@ -c $*.cpp # # Targets: # all: $(TARGET) $(TARGET): $(OBJS) $(LINK) $(FLAGS) -o $(TARGET) $(OBJS) $(LFLAGS) clean: -/bin/rm -f *.d *.o $(TARGET) make.dep: $(DEPENDENCIES) -cat $(DEPENDENCIES) > $@ include make.dep
pdriver.cpp
#include <cstdlib> #include <iostream> #include <sstream> #include <time.h> using namespace std; void permute (int[], int); int main(int argc, char** argv) { if (argc != 3) { cerr << "When you run this program, you must supply two parameters.\n" << "The first is the size of the array you want to permute.\n" << "The second is the number of trials you want to perform.\n" << "\n" << "For example, if you called this program pdriver, you\n" << "might invoke it as:\n" << " pdriver 100 10 \n" << "to generate 10 random permutations of 100 elements each." << endl; return 1; } int N; int trials; { istringstream arg1 (argv[1]); arg1 >> N; istringstream arg2 (argv[2]); arg2 >> trials; } int *array = new int[N]; srand(time(0)); for (int t = 0; t < trials; t++) { permute (array, N); // for (int i = 0; i < N; ++i) cout << array[i] << ' '; cout << endl; } return 0; }
permute.cpp
#include <cstdlib> #include <algorithm> #include <vector> using namespace std; unsigned rnd(unsigned limit) { return rand() % limit; } // Generate a random permutation of the integers from // 0 .. n-1, storing the results in array a. // void permute (int a[], int n) { for (int i = 0; i < n; i++) { // Guess at a value to put into a[i] int guess = rnd(n); while (find(a, a+i, guess) != a+i) { // If it's one that we've already used, guess again. guess = rnd(n); } a[i] = guess; } }