Question: C++ can somebody help me create the main for this header file?? The main() routine first calls the routine init_vals() and initializes cnt to 0

C++ can somebody help me create the main for this header file??

Themain()routine first calls the routineinit_vals()and initializescnt to 0, and then calls theprint_list()to print out the names of people in circle. After that it locates the M^th person in the list, and using the member functionerase(),it removes that person from the list, and by calling theprint_list()prints out the current contents of the list. This process continues (in a loop) until only one person remains in the list.

o Ifi(with initial value 0) indicates the position of a person inlist L, then the statement:j = (i + (M 1))%L.size()returns the position of the M^th person from the positioni.

o Since the argument to theerase()function is an iterator, you can convert the index valuejto an iterator by theadvance(p, j)function, wherep = L.begin().

To store the names in an empty list, first change the size of the list to N, and then use thegenerate()function in the STL. The last argument to this function is the function objectSEQ(N), which is defined in the header filejosephus.h.

header file

#ifndef H_JOSEPHUS

#define H_JOSEPHUS

#include

#include

#include

#include

#include

#include

using namespace std;

#define NO_LETS 26 // no of letters in English alphabet

#define NO_ITEMS 12 // no of items printed on single line

// struct for input arguments-

struct args {

unsigned N, // no of initial people

M, // count to eliminate person

K; // frequency of printouts

args(int N, int M, int K)

{

}

};

// class to generate name tags for people

class SEQ {

private:

string id; // name tag for person

unsigned size, nd; // no of people, no of digits in name tags

// returns no of digits in name tags

unsigned find_nd ( const double& sz ) {

if ( ( sz / NO_LETS ) =>

else return ( find_nd ( sz / NO_LETS ) + 1 );

}

public:

// constructor for name-tag generator

SEQ ( const unsigned& s = 1 ) : size ( s ) {

double sz = ( double ) size / 9; nd = find_nd ( sz );

id = string ( nd, 'A' ); id [ nd - 1 ] = '1';

}

// returns next name tag in sequence

string operator ( ) ( ) {

string tmp = id; int i = nd - 1;

if ( id [ i ]

else {

id [ i ] = '1'; bool flag = true;

for ( i--; i >= 0 && flag; i-- )

if ( id [ i ]

else id [ i ] = 'A';

}

return tmp;

}

};

// reads and initializes all input arguments

void init_vals(list &L, args &in){

ifstream input(\"josephus.d\");

int N;

int M;

int K;

while ( input >> N, K, M);

in.N = N;

in.M = M;

in.K=K;

L.resize(N);

SEQ names;

generate(L.begin(),L.end(), names); //storing the soldier names in names

}

// prints all name tags for remaining people after elimination

void print_list ( const list &L, const unsigned&cnt ){

int No_ItemsPerLine=0;

for(int i=0;i

{

if(No_ItemsPerLine!=NO_ITEMS)

{

for (auto L : L)

cout \">\">

No_ItemsPerLine++;

}

else

{

for (auto L : L)

cout

No_ItemsPerLine=1;

}

}

}

#endif

josephus.d

41 3 7

OUTPUT

Number of people? 41 Index for elimination? 3 Index for printing? 7

Initial group of people ----------------------- A1 A2 A3 A4 A5 A6 A7 A8 A9 B1 B2 B3 B4 B5 B6 B7 B8 B9 C1 C2 C3 C4 C5 C6 C7 C8 C9 D1 D2 D3 D4 D5 D6 D7 D8 D9 E1 E2 E3 E4 E5

After eliminating 7th person ---------------------------- A1 A2 A4 A5 A7 A8 B1 B2 B4 B5 B7 B8 C1 C2 C4 C5 C6 C7 C8 C9 D1 D2 D3 D4 D5 D6 D7 D8 D9 E1 E2 E3 E4 E5

After eliminating 14th person ----------------------------- A2 A4 A5 A7 A8 B1 B2 B4 B5 B7 B8 C1 C2 C4 C5 C7 C8 D1 D2 D4 D5 D7 D8 E1 E2 E4 E5

After eliminating 21th person ----------------------------- A2 A4 A7 A8 B2 B4 B7 B8 C2 C4 C7 C8 D2 D4 D7 D8 E1 E2 E4 E5

After eliminating 28th person ----------------------------- A2 A4 A8 B2 B7 B8 C4 C7 D2 D4 D8 E2 E4

After eliminating 35th person ----------------------------- A2 A4 B7 C4 D4 D8

After eliminating 40th person ----------------------------- D4

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!