Answered step by step
Verified Expert Solution
Question
1 Approved Answer
0. Modify the postfix program post.cpp to handle both subtraction and division: Sample input: ./a.out 4 10 - 6 x 12 / Sample output: -3
0. Modify the postfix program post.cpp to handle both subtraction and division: Sample input: ./a.out 4 10 - 6 x 12 / Sample output: -3 1. Write a program to fill in a two-dimensional array of boolean values by setting a[i][j] to 1 if the greatest common divisor of i and j is 1. Else if the greatest common divisor is not 1, then set a[i][j] to 0. Sample Input: ./a.out 6 Sample Output: 0 0 0 0 0 0 0 1 1 1 1 1 0 1 0 1 0 1 0 1 1 0 1 1 0 1 0 1 0 1 0 1 1 1 1 0 2. Write a program to solve the Josephus problem, with the following modification: Sample Input: ./a.out n m p where n is the number of players and m is the count used for every odd turn while p is the count used for every even turn. ./a.out 5 2 3 Sample Output: Round 1: 1 -> 3 -> 4 -> 5 Round 2: 1 -> 3 -> 4 Round 3: 1 -> 4 Round 4: 1 Winner is 1. 3. When is a graph a tree? Write a program that will read from a file specified on the command line and determine from the graph's adjacency matrix whether or not it is a tree. Example: ./a.out graph.txt Output: The graph is a tree! Contents of graph.txt will be something like this: 5 0 1 0 0 0 1 0 1 1 1 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0
______*Post.cpp*______
#include#include #include "stack.cpp" using namespace std; int main(int argc, char *argv[]) { char *a = argv[1]; int i, div, N = strlen(a); stack save(N); for(i = 0; i = '0') && (a[i] <= '9')) save.push(a[i] -'0'); } cout << save.pop() <
______________________
______*Josphesus*________
#include#include using namespace std; struct node { int key; node *next;}; int main(int argc, char* argv[]){ if(argc >2) { int i, N = atoi(argv[1]), M = atoi(argv[2]); node *t, *x; t = new node; t->key = 1; x = t; for(i = 2; i<=N; i++){ t->next = new node; t = t->next; t->key = i; } t->next = x; while(t != t->next){ for(i = 1; i next; cout << t->next->key<<" has dropped out "<< endl; x = t->next; t->next = x->next; delete x; } cout << "winner is " << t->key << endl; } return 0; } ____________________________
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started