Write C Program Finds Factorial Given Number Q43877377

Write a C program that finds the factorial of given number .

Expert Answer


Answer to Write a C program that finds the factorial of given number ….

Write C Program Fixes List Bank Card Numbers Miss One Digits Restore Digit Others Pair Adj Q43794613

Write a c++ program that fixes a list of bank card numbers. Someof them just miss one of digits and you should restore this digit.Others have a pair of adjacent digits swapped – you are to find theleftmost pair which, if swapped, makes valid cardnumber.

All the card numbers would be 16 digits long.

Input data contain a list of workers who havetheir card numbers incorrect.
Next lines contain a single card number each. If the numbercontains “?” (question mark) instead of some digit – this digitshould be restored. If all digits are present, then “swap-error”should be fixed.
Answer should contain a list of “fixed” cardnumbers.

input data:

4

?942682966937054 1217400151414995 2146133934?671142553514623364925

answer:

3942682966937054 1217040151414995 21461339346671142553514623369425

______________________________________________________________________________________

I need some help with my program. It is able to find a value toreplace the “?” with, but it does not find the right value for allof the test cases above. I also wrote a function(not included inbelow code), which use if statement to branch when the string doesnot contain “?” and deal with swap errors. For that, my approachwas to swap adjacent values, but I was able to get the right valueoutput to match the output sample above. I believe a map would behelpful to deal with this program, but I am not familiar with mapas data structures. I would appreciate your input. Since this is myfirst time trying to work with map, I would appreciate commentsinside the code. Also, I use Luhn Algorithm to check if a card isvalid or not.

—————————————————————————————————————————————————

#include <iostream>

#include <string>

#include <vector>

#include <array>

using namespace std;

void replace(int* a, int* b)

{

*b = *a;

}

void replace2(char* x, char* y)

{

*y = *x;

}

void eraseDemo(string str, int index)

{

str.erase(str.begin() + index);

}

int checkLuhn(string myString)

{

int x = myString.size();

int count = 0;

int val = 0;

int sum = 0;

char sign = ‘?’;

vector<int> arr;

size_t found = myString.find(sign);

if (found != string::npos)

{

eraseDemo(myString, found);

myString = myString;

x–;

}

while(count < x)

{

arr.push_back((int)myString[count] – 48);

count++;

}

int xx = arr.size()-1;

while(xx >= 0)

{

val = arr[xx] * 2;

if(val > 9)

{

val = val – 9;

}

replace(&val, &arr[xx]);

xx = xx – 2;

}

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

{

sum = sum + arr[ii];

}

return sum;

}

char Sum(string input)

{

int s = checkLuhn(input);

int ss = (s * 9) % 10;

char c = ss;

return c;

}

int main()

{

string x = “?942682966937054”;

char sign = ‘?’;

string result;

int mis = 0;

size_t found = x.find(sign);

mis = (checkLuhn(x) * 9) % 10;

Sum(x);

char s = ‘0’ + Sum(x);

replace2(&s , &x[found]);

cout << endl;

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

{

cout << x[xx];

}

cout << endl;

return 0;

}

Expert Answer


Answer to Write a c++ program that fixes a list of bank card numbers. Some of them just miss one of digits and you should restore …

Write C Program Following Ask User Enter Option Pick Infix Prefix Postfix Allow User Enter Q43810881

Write a C++ program that will do the following:

  1. Ask the user to enter the option to pick between infix, prefix,or postfix.
  2. Allow the user to enter a mathematical expression per theoption above.
  3. Allow the user to enter the option to pick between infix,prefix, or postfix.
  4. Ensure that the user does not pick the same exact optionagain.
  5. Validate that the expression entered is correct per the optionpicked in step 1.
  6. Evaluate the expression entered per the option selected in step1.
  7. Display the value produced in the above step.
  8. Convert the expression to be represented per the option pickedin step 3.
  9. Display the new expression after being converted in the abovestep.
  10. Evaluate the expression after being converted.
  11. Display the value produced in the above step.

Provide a screen shot of execution / output

Expert Answer


Answer to Write a C++ program that will do the following: Ask the user to enter the option to pick between infix, prefix, or postf…

Write C Program Following Write Function Finds Difference Two Numbers Function Gets 2 Inpu Q43858409

Write the Cprogram that does the following.

Write a function whichfinds the difference of two numbers. Your function gets 2 inputnumbers for example a and b and finds what is the difference ofthem, |a-b|. For example:

Difference(4, 8) =4

Expert Answer


Answer to Write the C program that does the following. Write a function which finds the difference of two numbers. Your function g…

Write C Program Gradec Includes Function Calculateaverage Calculate Average Arbitrary Numb Q43826010

write a C program, grade.c, which includes a function,

calculateAverage(), that can calculate the average ofan arbitrary number of test scores.

your program will not know in advance how many test scores willbe entered into your function

so you will need to use a sentinel value (-1) to terminate thewhile loop used to collect the test scores.

the test scores are integers in the range 0 to 100 and the testscore average should be output to two decimal places.

be sure that the user prompts and grades input into the programare displayed in the output file.

provided below is the main() function that I would likeyou to use for your program:

int main (void){

int I;

fopen_s(&fp, “csis.txt”, “w”);

for (i = 1; i <= 4; ++i) {

calculateAverage();

}

fclose(fp);

return 0;

}

please do not modify the main() function. it shouldappear as the first function in the program.

Be sure to use function prototypes for each of the functionsthat are used in your program.

Note that the first for loop invokes thecalculateAverage() function four times.

Each time the calculateAverage() function is invoked, adifferent set of test grades will be entered.

Please be sure to use the data shown below.

First: 78, 93, 45, 88, 89, -1

second: 87, 68, 100, -1

third: 84, 86, 90, 86, 96, 68, 82, -1

fourth: -1

Be sure that your code does not attempt to divide by zero forthe fourth run of the program.

Expert Answer


Answer to write a C program, grade.c, which includes a function, calculateAverage(), that can calculate the average of an arbitrar…

Write C Program Implement Functions 1 Function Returning Integer 2 Function Returning Floa Q43784676

Write any C# Program where You Implement these functions:

1. A function Returning an integer

2. A function Returning a Float

3. A function Returning a Double

4. A function Returning a String

5. A function Returning any array

6. A function Returning a pointer

7. Also, Implement the concept of array of pointers

You can Write any program as long as these functions existwithin. The goal is to have an understanding of these concepts.

Expert Answer


Answer to Write any C# Program where You Implement these functions: 1. A function Returning an integer 2. A function Returning a F…

Write C Program Input File Five Lines Create Five New Files File Contains One Line Q43865924

Write a c program. Input is a File with five lines.Create five new files, with each file contains one lineeach.

Expert Answer


Answer to Write a c program. Input is a File with five lines. Create five new files, with each file contains one line each….

Write C Program Inputs Contents File Line Line Outputs Line Console Program Starts Inputti Q43856576

Write a C++ program that inputs the contents of a file line byline, and outputs each line to the console. The program starts byinputting the name of the file from the keyboard, opens the file,and then checks to make sure the file was opened successfully. Ifnot, the program outputs “**file not found” and returns.

If the file was opened successfully, the program proceeds toread the file line by line, outputting each line to the consolealong with its line number. Assume each line of the input filecontains a single word. For example, suppose the file “input1.txt”contains the following:

apple

banana

pear

pizza

Given the filename “input1.txt”, your program should produce thefollowing output:

line 1: apple

line 2: banana

line 3: pear

line 4: pizza

main.cpp

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
string filename;

cout << “please enter filename> “;
cin >> filename; // input filename:
cout << endl;

//
// TODO:
//

return 0;
}

Expert Answer


Answer to Write a C++ program that inputs the contents of a file line by line, and outputs each line to the console. The program s…

Write C Program Load Two Column Numbers Arithmetic Operations Data Points Following Steps Q43844148

Write a c++ program toload two column of numbers, do arithmetic operations to the datapoints by following the steps below carefully. Output the computedresults to the specified output files

Steps to complete.

0. Download the datafile named Datafile1.data from the file area of the assignment.

1. Load two columns ofdata points, each column into a storage area, preferably avector.

2. Add each positionof the data and store it in another storage area.

3. Multiply eachposition of the data and store it to another storage area.

4. Write the resultsof addition and multiplication to file namedOutput-Multiplication.data and Output-Addition.data

Datafile1.data

9.144548371       0.62072663
7.766500067       1.107554175
6.428523445       0.409904615
4.864271967       1.142139412
7.064106885       1.138740729
2.262955152       1.198965847
9.800966285       0.624420569
8.466914743       0.172152387
7.089199692       0.650149663
6.042680886       0.526675179
1.320701358       0.893658642
3.576178301       0.966546628
4.939756105       0.53583099
3.386905283       0.24428521
5.231554752       0.660683916
3.736280728       0.378121052
7.527971435       0.917047269
2.533630929       1.029850114
9.188222671       0.237647807
1.800088589       0.763132902
9.702171329       1.187835787
4.713240732       0.602808579
0.350114291       0.126105779
1.375572924       0.534626533
3.699384174       0.670885379
7.183110563       1.327536861
7.434890545       1.174302317
9.781202522       1.271484048
7.153021655       0.99647769
0.516259776       0.868291689
9.637573135       0.596947716
7.056519481       0.350322259
0.160533268       0.565683307
9.008315924       0.919842547
9.173718748       0.593500412
6.921833783       0.015908284
6.736418485       0.719292318
3.353631576       1.363438995
1.604967361       0.679785674
5.672035588       0.171718917
7.794867595       0.550310846
5.889160186       0.07760882
1.690701207       0.829202546
4.155650455       0.94739278
6.018503489       0.989127529
1.46468541       1.171169011
2.670443291       0.505688273
8.22853784       0.514127061
9.631840542       0.238298413
1.669453846       1.27499486
3.311515543       0.789657118
5.969493897       0.053853209
2.478574394       1.206080543
7.696244495       0.099599082
3.769765061       1.193693451
1.992200015       0.895544331
4.030882115       0.398607671
2.939993773       0.360149058
8.499182913       0.645159168
1.33467738       0.264472403
3.475730127       0.826362657
7.471431245       1.220818624
6.140279634       0.462733534
3.740656241       1.363952935
5.174154405       1.157155608
9.466008548       0.261690906
9.225005657       0.158991829
7.061522707       0.200296564
2.527050453       0.668705617
3.989058951       0.659984653
5.969333965       0.297768248
6.813173789       1.23032852
7.47467435       0.289477322
0.27004337       0.808100642
0.226724804       0.947863653
8.491775489       0.703714179
9.67169797       0.439579426
7.171630039       0.893035833
8.435125276       0.053497387
1.740878827       1.135864744
1.624571489       0.537973501
9.398492585       1.285333242
9.855769556       1.156707773
5.536670988       0.524629176

COMPUTER SCIENCE…PLEASE HELP!!

Expert Answer


Answer to Write a c++ program to load two column of numbers, do arithmetic operations to the data points by following the steps be…

Write C Program Load Two Column Numbers Arithmetic Operations Data Points Following Steps Q43884091

Write a c++ program toload two column of numbers, do arithmetic operations to the datapoints by following the steps below carefully. Output the computedresults to the specified output files

Steps to complete.

0. Download the datafile named Datafile1.data from the file area of the assignment. (Donot change the file name to .txt. Open the file in notepad (win) orview/vi/vim (linux) or any viewer of your choice if you like to seethe data)

1. Create distinctfunctions for this project.

2. Load two columns ofdata points, each column into a storage area of a class where thedata storage is a vector .

3. Add each positionof the data and store it in another class where the data storage isa vector.

4. Multiply eachposition of the data and store it to another class where the datastorage is a vector.

5. Write the resultsof addition and multiplication to a file namedOutput-MultAdd-class.data and Output-Addition-class.data. Columnsof the output file is value1, value2, Addition, Multiplication in anicely formatted fashion.  

Datafile1.data

9.144548371       0.62072663
7.766500067       1.107554175
6.428523445       0.409904615
4.864271967       1.142139412
7.064106885       1.138740729
2.262955152       1.198965847
9.800966285       0.624420569
8.466914743       0.172152387
7.089199692       0.650149663
6.042680886       0.526675179
1.320701358       0.893658642
3.576178301       0.966546628
4.939756105       0.53583099
3.386905283       0.24428521
5.231554752       0.660683916
3.736280728       0.378121052
7.527971435       0.917047269
2.533630929       1.029850114
9.188222671       0.237647807
1.800088589       0.763132902
9.702171329       1.187835787
4.713240732       0.602808579
0.350114291       0.126105779
1.375572924       0.534626533
3.699384174       0.670885379
7.183110563       1.327536861
7.434890545       1.174302317
9.781202522       1.271484048
7.153021655       0.99647769
0.516259776       0.868291689
9.637573135       0.596947716
7.056519481       0.350322259
0.160533268       0.565683307
9.008315924       0.919842547
9.173718748       0.593500412
6.921833783       0.015908284
6.736418485       0.719292318
3.353631576       1.363438995
1.604967361       0.679785674
5.672035588       0.171718917
7.794867595       0.550310846
5.889160186       0.07760882
1.690701207       0.829202546
4.155650455       0.94739278
6.018503489       0.989127529
1.46468541       1.171169011
2.670443291       0.505688273
8.22853784       0.514127061
9.631840542       0.238298413
1.669453846       1.27499486
3.311515543       0.789657118
5.969493897       0.053853209
2.478574394       1.206080543
7.696244495       0.099599082
3.769765061       1.193693451
1.992200015       0.895544331
4.030882115       0.398607671
2.939993773       0.360149058
8.499182913       0.645159168
1.33467738       0.264472403
3.475730127       0.826362657
7.471431245       1.220818624
6.140279634       0.462733534
3.740656241       1.363952935
5.174154405       1.157155608
9.466008548       0.261690906
9.225005657       0.158991829
7.061522707       0.200296564
2.527050453       0.668705617
3.989058951       0.659984653
5.969333965       0.297768248
6.813173789       1.23032852
7.47467435       0.289477322
0.27004337       0.808100642
0.226724804       0.947863653
8.491775489       0.703714179
9.67169797       0.439579426
7.171630039       0.893035833
8.435125276       0.053497387
1.740878827       1.135864744
1.624571489       0.537973501
9.398492585       1.285333242
9.855769556       1.156707773
5.536670988       0.524629176

COMPUTER SCIENCE…PLEASE HELP!!

Expert Answer


Answer to Write a c++ program to load two column of numbers, do arithmetic operations to the data points by following the steps be…