Using C Implement Badstoogesort Pseudocode Sort Array Integers Value Input Parameter Progr Q43901245

Using C++

Consider the following pseudocode for a sorting algorithm, for 0 < a < 1 and n > 1. badSort(A[O...n - 1]) if (n = 2) and (A[0

Implement badStoogeSort from pseudocode to sort an array ofintegers. The value of α should be an input parameter to yourprogram. Implement the algorithm in C/C++. Your program should beable to read inputs from a file called “data.txt”, where the firstvalue of each line is the number of integers that need to besorted, followed by the integers. The output will be written to afile called “bad.out”. Then, Modify the code to collectrunning time data. Call the new timing program badStoogeSort.Instead of reading arrays from the file data.txt and sorting, youwill now generate arrays of size n containing random integer valuesfrom 0 to 10,000 to sort. Use the system clock to record therunning times of each algorithm for n = 5000, 10000, 15000, 20,000,…. for two values of α = 2/3 and α = 3/4. You may need to modifythe values of n if an algorithm runs too fast or tooslow

Consider the following pseudocode for a sorting algorithm, for 0 < a < 1 and n > 1. badSort(A[O…n – 1]) if (n = 2) and (A[0] > A[1]) swap A[0] and A[1] else if (n > 2) m = fa.nl badSort(A[O…m – 1]) badSort(A[n – m…n – 1]) badSort(A[O…m – 1]) Show transcribed image text Consider the following pseudocode for a sorting algorithm, for 0 A[1]) swap A[0] and A[1] else if (n > 2) m = fa.nl badSort(A[O…m – 1]) badSort(A[n – m…n – 1]) badSort(A[O…m – 1])

Expert Answer


Answer to Using C++ Implement badStoogeSort from pseudocode to sort an array of integers. The value of α should be an input param…

Using C Implement Function Ranges Takes Input Prints Ranges E Minimum Maximum Legal Values Q43861448

Using C:

Implement the function ranges that takes no input and prints theranges (i.e., the minimum and maximum legal values) of the typeschar, short, int, long, and long long, both signed and unsigned.You should do this by printing appropriate constants defined in theheader file /usr/include/limits.h (this is why hw1.c starts with#include <limits.h>). This should print something like:

signed charminimum value: -128maximum value: 127unsigned charminimum value: 0maximum value: 255signed shortminimum value: -32768maximum value: 32767

Void ranges() {

//IMPLEMENT THIS

}

Expert Answer


Answer to Using C: Implement the function ranges that takes no input and prints the ranges (i.e., the minimum and maximum legal va…

Using C Language Write Program Find Smallest Number 3 Given Integer Number Using Function Q43790107

using c++ language

Write program to find the smallest number from 3 given integernumber using function. Then try 5 given number.

Expert Answer


Answer to using c++ language Write program to find the smallest number from 3 given integer number using function. Then try 5 give…

Using C Luhn Algorithm Fix Cards Swap Errors Facing Swap Error Pair Adjacent Digits Swappe Q43802280

Using c++ and the Luhn Algorithm, I have to fix cards with swaperrors.  When facing a swap error, a pair of adjacentdigits are swapped until the right card combination is found. I amto find the leftmost pair which, if swapped, makesvalid card number. The checkLuhn function get the sum of all of thevalues in a string. I use that sum to check if the card are validby using checkLuhn % 10. In addition, I take from stdin the numberof cards the user needs to check. My issue is that my program workwhen I hard code a value inside a single string value, and applythe checkLuhn on it. However, when I try to use the function insidea loop to make operation equals to use input, I get 1 of the inputcards wrong( here 25535146….).In addition, I also getsegmentation fault for large data inputs. Below is the working hardcoded program along the version which requires user input. I haveattached pictures of the output I get. Your feedback will beappreciated.

sample input data:

2

1217400151414995

2553514623364925

sample answer:

1217040151414995

2553514623369425

_____________________________________________________________________________________________________________

//Hard coded version

#include <iostream>

#include <string>

#include <vector>

#include <array>

#include <limits>

using namespace std;

void replace(char* a, char* b)

{

*b = *a;

}

int checkLuhn(string myString){

int x = myString.size();

int sum = 0;

int i = 0;

char c = ‘ ‘;

for(int v = x – 1; v >= 0; –v){

if(v % 2 == 0){

i = (int)myString[v] – 48;

i = i * 2;

if(i > 9){

i = i – 9;

}

c = ‘0’ + i;

replace(&c , &myString[v]);

}}

for(int ii = 0; ii < x; ii++){

sum = sum + (int)myString[ii] – 48;

}return sum;

}

int main(){

string x = “2553514623364925”;

int n = 0;

int nn = 1;

if(checkLuhn(x) != 0){

while(checkLuhn(x) % 10 != 0){

if(n == 0 || nn == 1){

swap(x[n],x[nn]);

}

else

{

swap(x[n – 2],x[nn – 2]);

swap(x[n],x[nn]);

}

n = n + 2;

nn = nn + 2;

}

}

cout << endl;

for(int i = 0; i < x.size(); i++)

{

cout << x[i];

}

return 0;

}

2553514623369425:

———————————————————————————-

//same but with added user input

#include <iostream>

#include <string>

#include <vector>

#include <array>

#include <limits>

using namespace std;

void replace(char* a, char* b)

{

*b = *a;

}

int checkLuhn(string myString)

{

int x = myString.size();

int sum = 0;

int i = 0;

char c = ‘ ‘;

for(int v = x – 1; v >= 0; –v)

{

if(v % 2 == 0)

{

i = (int)myString[v] – 48;

i = i * 2;

if(i > 9)

{

i = i – 9;

}

c = ‘0’ + i;

replace(&c , &myString[v]);

}

}

for(int ii = 0; ii < x; ii++)

{

sum = sum + (int)myString[ii] – 48;

}

return sum;

}

int main()

{

int count;

string x;

int s = 0;

int n = 0;

int nn = 1;

cin >> count;

cin.clear();

cin.ignore(numeric_limits<streamsize>::max(), ‘n’);

vector <string> input;

while(getline(cin,x) && s < count)

{

input.push_back(x);

s++;

}

for(int j = 0; j < count; j++)

{

if(checkLuhn(input[j]) != 0)

{

while(checkLuhn(input[j]) % 10 != 0)

{

if(n == 0 || nn == 1)

{

swap(input[j][n],input[j][nn]);

}

else

{

swap(input[j][n – 2],input[j][nn – 2]);

swap(input[j][n],input[j][nn]);

}

n = n + 2;

nn = nn + 2;

}

}

}

cout << endl;

for(int x = 0; x < count; x++)

{

cout << input[x];

cout << endl;

}

return 0;

}

1217400151414995 2553514623364925 1217040151414995 2553154632364925

2553514623369425: 1217400151414995 2553514623364925 1217040151414995 2553154632364925 Show transcribed image text 2553514623369425:
1217400151414995 2553514623364925 1217040151414995 2553154632364925

Expert Answer


Answer to Using c++ and the Luhn Algorithm, I have to fix cards with swap errors. When facing a swap error, a pair of adjacent dig…

Using C Modify Code Collect Running Time Data Call New Timing Program Badstoogesort Instea Q43899135

Using C++ Modify the code to collect running time data. Call the new timing program badStoogeSort. Instead of reading arrays from the file data.txt and sorting, you will now generate arrays of size n containing random integer values from 0 to 10,000 to sort. Use the system clock to record the running times of each algorithm for n = 5000, 10000, 15000, 20,000, …. for two values of α = 2/3 and α = 3/4. You may need to modify the values of n if an algorithm runs too fast or too slow#include <iostream>#include <string>#include <fstream>#include <cmath>using namespace std;/*our base case for the sorting will be when there are only 2 elementsif we meet that condition we compare the 2 elements and perform a swap operation if neededelse we perform a recursive call on 2/3 of the size of the arraywe are creating 3 sub problems1 focuses on the initial 2/3rd of our data the other will focus on the other 2/3rd of our dataAnother way to visualize it is we analyze 2/3rd from our starting point firstwe them analyze 2/3rd from our end pointour last recursive call is to analyze the initial 2/3rd againwe continue until we only have 2 elements than we swap if needed and trace back to the callsstill follows the divide and conquer rules.we divide into 2/3rdswe conquer by swapping first and last elements of a subproblems*/void stoogeSort(int arr[], int start, int end){ int size = end – start+1; // base case when there are only 2 elements if (size == 2) { // condition to check if we need to perform a swap operation if (arr[start] > arr[end]) { int temp = arr[start]; arr[start] = arr[end]; arr[end] = temp; } } else if (size > 2) { // here we get the index value that represents our focal point // you can view this as our midpoint but instead of half we are focused with what index falls at 2/3rds of our array int point = size/3; // we recursively sort the first 2/3rd stoogeSort(arr, start, end – point); // here we do the second 2/3rd stoogeSort(arr, start+point, end); // we perform another recursion on the first 2/3rd again to verify // this repeated call is in the case if there was a swap that took place in the second call stoogeSort(arr, start, end – point); }}int main(){ ifstream readFile(“data.txt”); ofstream outputFile(“stooge.out”); while (!readFile.eof()) { int size; int* list; // getting the number of elements readFile >> size; // allocating enough room for our dynamic array list = new int[size]; // getting the elements for our dynamic array int temp; for (int x = 0; x < size; x++) { readFile >> temp; list[x] = temp; } // Sorting our values stoogeSort(list, 0, size-1); // writing the result to the insert.out file for (int x = 0; x < size; x++) { outputFile << list[x] << ” “; } outputFile << endl; // deallocation delete[] list; } // closing our file streams readFile.close(); outputFile.close(); return 0;}

Expert Answer


Answer to Using C++ Modify the code to collect running time data. Call the new timing program badStoogeSort. Instead of reading a…

Using C Modify Code Collect Running Time Data Call New Timing Program Badstoogesort Instea Q43903378

Consider the following pseudocode for a sorting algorithm, for 0 < a < 1 and n > 1. badSort(A[O...n - 1]) if (n = 2) and (A[0Using C++ Modify the code to collect running time data. Call the new timing program badStoogeSort. Instead of reading arrays from the file data.txt and sorting, you will now generate arrays of size n containing random integer values from 0 to 10,000 to sort. Use the system clock to record the running times of each algorithm for n = 5000, 10000, 15000, 20,000, …. for two values of α = 2/3 and α = 3/4. You may need to modify the values of n if an algorithm runs too fast or too slow#include <iostream>#include <string>#include <fstream>#include <cmath>using namespace std;/*our base case for the sorting will be when there are only 2 elementsif we meet that condition we compare the 2 elements and perform a swap operation if neededelse we perform a recursive call on 2/3 of the size of the arraywe are creating 3 sub problems1 focuses on the initial 2/3rd of our data the other will focus on the other 2/3rd of our dataAnother way to visualize it is we analyze 2/3rd from our starting point firstwe them analyze 2/3rd from our end pointour last recursive call is to analyze the initial 2/3rd againwe continue until we only have 2 elements than we swap if needed and trace back to the callsstill follows the divide and conquer rules.we divide into 2/3rdswe conquer by swapping first and last elements of a subproblems*/void stoogeSort(int arr[], int start, int end){ int size = end – start+1; // base case when there are only 2 elements if (size == 2) { // condition to check if we need to perform a swap operation if (arr[start] > arr[end]) { int temp = arr[start]; arr[start] = arr[end]; arr[end] = temp; } } else if (size > 2) { // here we get the index value that represents our focal point // you can view this as our midpoint but instead of half we are focused with what index falls at 2/3rds of our array int point = size/3; // we recursively sort the first 2/3rd stoogeSort(arr, start, end – point); // here we do the second 2/3rd stoogeSort(arr, start+point, end); // we perform another recursion on the first 2/3rd again to verify // this repeated call is in the case if there was a swap that took place in the second call stoogeSort(arr, start, end – point); }}int main(){ ifstream readFile(“data.txt”); ofstream outputFile(“stooge.out”); while (!readFile.eof()) { int size; int* list; // getting the number of elements readFile >> size; // allocating enough room for our dynamic array list = new int[size]; // getting the elements for our dynamic array int temp; for (int x = 0; x < size; x++) { readFile >> temp; list[x] = temp; } // Sorting our values stoogeSort(list, 0, size-1); // writing the result to the insert.out file for (int x = 0; x < size; x++) { outputFile << list[x] << ” “; } outputFile << endl; // deallocation delete[] list; } // closing our file streams readFile.close(); outputFile.close(); return 0;}Consider the following pseudocode for a sorting algorithm, for 0 < a < 1 and n > 1. badSort(A[O…n – 1]) if (n = 2) and (A[0] > A[1]) swap A[0] and A[1] else if (n > 2) m = fa.nl badSort(A[O…m – 1]) badSort(A[n – m…n – 1]) badSort(A[O…m – 1]) Show transcribed image text Consider the following pseudocode for a sorting algorithm, for 0 A[1]) swap A[0] and A[1] else if (n > 2) m = fa.nl badSort(A[O…m – 1]) badSort(A[n – m…n – 1]) badSort(A[O…m – 1])

Expert Answer


Answer to Using C++ Modify the code to collect running time data. Call the new timing program badStoogeSort. Instead of reading ar…

Using C Need Implement Topological Sorting Requirenments Include Represent Diagraph Adjace Q43784744

Using C++ need to implement topological sorting

Requirenments:

can only include <iostream> or <iostream.h>

Represent the diagraph with Adjacency List

Determine the data structures for the proccess of improvedtopological sorting

Design a C++ programm implementing the improved topologicalsorting

Expert Answer


Answer to Using C++ need to implement topological sorting Requirenments: can only include or Represent the diagraph with Adjacency…

Using C Program Create Order Entry Screen Program C Give Total Individual Pizza Order Pizz Q43898510

Using C# Program.

Create an order entry screen program in C# to give a total foran individual pizza order. The Pizza order should have radiobuttons for small $7, medium $9, and large $12 choices for thepizza. There should be a checkbox for drink (where a drink is $2added if it is checked and nothing added if it is not checked.Include a textbox for the customer’s name.

Have a button to calculate the subtotal (pizza choice andwhether there is a drink or not on the order), tax (.07 of thesubtotal) and the total (subtotal plus tax). Put these calculatedvalues into labels on the screen for the user. Also have anotherlabel show a message to show the customer’s pizza is ready withtheir name from the textbox.

Include a button to clear the order, it should clear thetextbox, set the radio buttons back to having the large oneselected, the checkbox for the drink should be unchecked, andtextbox and the message label should be cleared.

Make sure to rename the buttons and the output labels, theyshould not be named “button1”, “label1”, they should havedescriptive names as will be discussed in class.

Expert Answer


Answer to Using C# Program. Create an order entry screen program in C# to give a total for an individual pizza order. The Pizza or…

Using C Programming Language Implement Heapsort Manner Described Class Example Code Use Gu Q43871973

Using the C programming language implement Heapsort in the manner described in class. Here is some example code to use as a guideline. Remember, you need only implement the sort algorithm, both the comparison and main functions have been provided./* * * after splitting this file into the five source files: * * srt.h, main.c, srtbubb.c, srtinsr.c, srtmerg.c * * compile using the command: * * gcc -std=c99 -DRAND -DPRNT -DTYPE=(float | double) -D(BUBB | HEAP | INSR | MERG) *.c * *//* * * srt.h file * */#ifndef SRT_H#define SRT_H#include #define MAX_BUF 256#define swap(qx,qy,sz) do { char buf[MAX_BUF]; char *q1 = qx; char *q2 = qy; for (size_t m, ms = sz; ms > 0; ms -= m, q1 += m, q2 += m) { m = ms < sizeof(buf) ? ms : sizeof(buf); memcpy(buf, q1, m); memcpy(q1, q2, m); memcpy(q2, buf, m); } } while (0)void srtbubb(void *, size_t, size_t, int (*)(const void *, const void *));void srtheap(void *, size_t, size_t, int (*)(const void *, const void *));void srtinsr(void *, size_t, size_t, int (*)(const void *, const void *));void srtmerg(void *, size_t, size_t, int (*)(const void *, const void *));#endif /* SRT_H *//* * * main.c file * */#include #include #include #include “srt.h”static int compare(const void *, const void *);int main(int argc, char *argv[]) { int nelem = argc == 2 ? atoi(argv[1]) : SHRT_MAX; TYPE *a = calloc(nelem, sizeof(TYPE));#ifdef RAND for (int i = 0; i < nelem; ++i) { a[i] = (TYPE)rand() / RAND_MAX; }#else for (int i = 0; i < nelem; ++i) { a[i] = i; }#endif#if defined BUBB srtbubb(a, nelem, sizeof(TYPE), compare);#elif defined HEAP srtheap(a, nelem, sizeof(TYPE), compare);#elif defined INSR srtinsr(a, nelem, sizeof(TYPE), compare);#elif defined MERG srtmerg(a, nelem, sizeof(TYPE), compare);#else qsort(a, nelem, sizeof(TYPE), compare);#endif#ifdef PRNT for (int i = 0; i < nelem; ++i) { printf(“%fn”, a[i]); }#else for (int i = 0; i < nelem – 1; ++i) { if (a[i] > a[i + 1]) { printf(“failn”); goto end; } } printf(“passn”);#endifend: free(a); return 0;}static int compare(const void *p1, const void *p2) { if (*(TYPE *)p1 < *(TYPE *)p2) { return -5; } else if (*(TYPE *)p1 > *(TYPE *)p2) { return +5; } return 0;}/* * * srtbubb.c file * */#include #include #include “srt.h”void srtbubb(void *base, size_t nelem, size_t size, int (*compar)(const void *, const void *)) { for (size_t i = nelem – 1; i > 0; –i) { bool sorted = true; for (size_t j = 0; j < i; ++j) { char *qj = (char *)base + size * j; char *qn = qj + size; if (compar(qj, qn) > 0) { swap(qj, qn, size); sorted = false; } } if (sorted) { break; } } return;}/* * * srtinsr.c file * */#include #include #include “srt.h”void srtinsr(void *base, size_t nelem, size_t size, int (*compar)(const void *, const void *)) { char buf[size], *qb = base; for (size_t i = 1; i < nelem; ++i) { memcpy(buf, qb + size * i, size); size_t j = i; while (j > 0 && compar(buf, qb + size * (j – 1)) < 0) { memcpy(qb + size * j, qb + size * (j – 1), size); –j; } memcpy(qb + size * j, buf, size); } return;}/* * * srtmerg.c file * */#include #include #include “srt.h”void srtmerg(void *base, size_t nelem, size_t size, int (*compar)(const void *, const void *)) { char *qb = base, *ql, *qr, *qt; size_t i, j, l, r; if (nelem <= 1) { return; } else if (nelem == 2) { if (compar(qb, qb + size) > 0) { swap(qb, qb + size, size); } return; } l = nelem / 2; r = nelem – l; ql = qt = malloc(size * l); memcpy(ql, qb, size * l); qr = qb + size * l; srtmerg(ql, l, size, compar); srtmerg(qr, r, size, compar); i = 0; j = l; while(i < l && j < nelem) { if (compar(ql, qr) <= 0) { memcpy(qb, ql, size); qb += size; ql += size; ++i; } else { memcpy(qb, qr, size); qb += size; qr += size; ++j; } } if (i < l) { memcpy(qb, ql, size * (l – i)); } free(qt); return;}

Expert Answer


Answer to Using the C programming language implement Heapsort in the manner described in class. Here is some example code to use …

Using C Programming Write Program Prompts User Input String Outputs String Pig Latin Form Q43780018

Using C programming, Write a program that prompts the user toinput a string and then outputs the string in the pig Latin form.The rules for converting a string into pig Latin form are asfollows: a. If the string begins with a vowel, add the string”-way” at the end of the string. For example, the pig Latin form ofthe string “eye” is “eye-way”. b. If the string does not begin witha vowel, first add “-” at the end of the string. Then rotate thestring one character at a time; that is, move the first characterof the string to the end of the string until the first character ofthe string becomes a vowel. Then add the string “ay” at the end.For example, the pig Latin form of the string “There” is”ere-Thay”. c. Strings such as “by” contain no vowels. In caseslike this, the letter y can be considered a vowel. So, for thisprogram the vowels are a, e, i, o, u, y, A, E, I, O, U, and Y.Therefore, the pig Latin form of “by” is “y-bay”. d. Strings suchas “1234” contain no vowels. The pig Latin form of the string”1234″ is “1234-way”. That is, the pig Latin form of a string thathas no vowels in it is the string followed by the string”-way”.

Expert Answer


Answer to Using C programming, Write a program that prompts the user to input a string and then outputs the string in the pig Lati…