#include<stdio.h>
#include<stdlib.h>
#include<string.h>
/* function that converts the change into count of 50,20,10,5 and stores the count in changeArray*/
int coinChange(int changeArray[10][4],int index,int change)
{
int count50=0,count20=0,count10=0,count5=0;
while(change > 0)
{
if(change > 0 && change <=95 && change% 5 == 0)
{
if(change >= 50)
{
change -= 50;
count50++;
}
else if(change >= 20)
{
change -= 20;
count20++;
}
else if(change>=10)
{
change -= 10;
count10++;
}
else if(change>=5)
{
change -= 5;
count5++;
}
}
}
changeArray[index][0]=count50;
changeArray[index][1]=count20;
changeArray[index][2]=count10;
changeArray[index][3]=count5;
return change;
}
/* function that reads 'coins.txt' and stores names in names array, coin values in coins array, compute change and stores change count in change array */
int readFromFile(char names[10][100],int coins[],int change[10][4])
{
int index=-1,i=0;
FILE *fp;
fp=fopen("coins.txt","r");
if(fp==NULL)
{
printf("File doesnot exists\n");
exit(0);
}
char line[128];
while(fgets(line,sizeof(line),fp)!=NULL)
{
index++;
int i=0;
while(line[i]!=' ')
{
names[index][i]=line[i];
i++;
}
names[index][i]='\0';
i++;
int value=0;
while(line[i]!='\n')
{
value=value*10+(int)line[i]-48;
i++;
}
coins[index]=value;
coinChange(change,index,value);
}
fclose(fp);
return index+1;
}
/* function that takes new name as input and search for it names array, if present then display its corresponding details else prints Not found */
void searchAndPrint(char names[10][100],char name[],int coins[10],int change[10][4],int index)
{
int found=-1,i,j;
int values[]={50,20,10,5};
for(i=0;i<10;i++) {
if(strcmp(names[i],name)==0)
{
found=i;
break;
}
}
if(found==-1)
printf("Not Found\n");
else
{
for(j=0;j<4;j++)
{
if(change[found][j]!=0)
printf("%d cents: %d\n",values[j],change[found][j]);
}
}
}
/* function that creates csv files and inserts all data into csv file */
void createAndInsertIntoCSV(char names[10][100],int coins[10],int change[10][4],int index)
{
FILE *fp=fopen("coins.csv","w+");
int i;
fprintf(fp,"%s,%s,%s,%s,%s,%s\n","Name","Change Value","50 count","20 count","10 count","5 count");
for(i=0;i<10;i++) fprintf(fp,"%s,%d,%d,%d,%d,%d\n",names[i],coins[i],change[i][0],change[i][1],change[i][2],change[i][3]);
}
int main()
{
char names[10][100];
int coins[10];
int change[10][4];
int index=readFromFile(names,coins,change); // index represents the no. of records in txt file
while(1)
{
printf("\n1--->Enter name\n2--->Exit\n\nEnter your choice:");
int choice;
scanf("%d",&choice);
if(choice==1)
{
char name[100];
printf("Customer:\n");
scanf("%s",name);
printf("Name: %s\n",name);
searchAndPrint(names,name,coins,change,index);
}
else
{
createAndInsertIntoCSV(names,coins,change,index);
printf("CSV file is generated and saved in present working directory with name \"coins.csv\"\n");
break;
}
}
}
I tried this code provided from an expert but for some reason, nothing is being shown on the console after I ran it. And the expert seems to have an output shown to him. is there any problem with this code?
Step by stepSolved in 2 steps with 1 images
- Common Time Zones Function Name: commonTimeZones() Parameters: code1( str ), code2( str) Returns: list of common time zones ( list ) Description: You and your friend live in different countries, but you figure there's a chance that both of you might be in the same time zone. Thus, you want to find out the list of possible time zones that you and your friend could both be in. Given two country codes, write a function that returns a list of the time zones the two countries have in common. Be sure not to include any duplicate time zones. If the two country codes do not have any common time zones, return the string 'No Common Time Zones' instead. Note: You can assume that the codes will always be valid. example test cases: >>> commonTimeZones('can', 'usa') [UTC-08:00', 'UTC-07:00', 'UTC-06:00', 'UTC-05:00', 'UTC-04:00] >>> commonTimeZones('rus', 'chn') [UTC+08:00] For this assignment, use the REST countries API (https://restcountries.com/#api-endpoints-v2). For all of your requests, make…arrow_forward#include <iostream>#include <cstdlib>#include <time.h>#include <chrono> using namespace std::chrono;using namespace std; void randomVector(int vector[], int size){ for (int i = 0; i < size; i++) { //ToDo: Add Comment vector[i] = rand() % 100; }} int main(){ unsigned long size = 100000000; srand(time(0)); int *v1, *v2, *v3; //ToDo: Add Comment auto start = high_resolution_clock::now(); //ToDo: Add Comment v1 = (int *) malloc(size * sizeof(int *)); v2 = (int *) malloc(size * sizeof(int *)); v3 = (int *) malloc(size * sizeof(int *)); randomVector(v1, size); randomVector(v2, size); //ToDo: Add Comment for (int i = 0; i < size; i++) { v3[i] = v1[i] + v2[i]; } auto stop = high_resolution_clock::now(); //ToDo: Add Comment auto duration = duration_cast<microseconds>(stop - start); cout << "Time taken by function: " << duration.count()…arrow_forward3. int count(10); while(count >= 0) { count -= 2; std::cout << count << endl;arrow_forward
- #include<stdio.h>#include<string.h>struct info{char names[100];int age;float wage;};int main(int argc, char* argv[]) {int line_count = 0;int index, i;struct info hr[10];if (argc != 2)printf("Invalid user_input!\n");else {FILE* contents = fopen (argv[1], "r");struct info in;if (contents != NULL) {printf("File has been opened successfully.\n\n");while (fscanf(contents, "%s %d %f\n",hr[line_count].names, &hr[line_count].age, &hr[line_count].wage) != EOF) {printf("%s %d %f\n", hr[line_count].names, hr[line_count].age, hr[line_count].wage);line_count++;}printf("\nTotal number of lines in document are: %d\n\n", line_count);fclose(contents);printf("Please enter a name: ");char user_input[100];fgets(user_input, 30, stdin);user_input[strlen(user_input)-1] = '\0';index = -1;for(i = 0; i < line_count; i++){if(strcmp(hr[i].names, user_input) == 0){index = i;break;}}if(index == -1)printf("Name %s not found\n", user_input);else{while(fread(&in, sizeof(struct info), 1,…arrow_forward#include using namespace std; void scanPrice (string [], double []); // Do not modify the code double printReceipt(string [], double[]); // Do not modify the code int main () { double sum; string item [3] = {"Vegetable","Egg", "Meat"}; double price [3];| %3D scanPrice (item,price); sum = RrintReceipt (item,price); cout Price: 10 The price of Vegetable is RM 2 The price of Egg is RM 3 The price of Meat is RM 10 Your total expenses is RM 15arrow_forwardplease use DEQUE #include <iostream>#include <string>#include <deque> using namespace std; const int AIRPORT_COUNT = 12;string airports[AIRPORT_COUNT] = {"DAL","ABQ","DEN","MSY","HOU","SAT","CRP","MID","OKC","OMA","MDW","TUL"}; int main(){// define stack (or queue ) herestring origin;string dest;string citypair;cout << "Loading the CONTAINER ..." << endl;// LOAD THE STACK ( or queue) HERE// Create all the possible Airport combinations that could exist from the list provided.// i.e DALABQ, DALDEN, ...., ABQDAL, ABQDEN ...// DO NOT Load SameSame - DALDAL, ABQABQ, etc .. cout << "Getting data from the CONTAINER ..." << endl;// Retrieve data from the STACK/QUEUE here } Using the attached shell program (AirportCombos.cpp), create a list of strings to process and place on a STL DEQUE container. Using the provided 3 char airport codes, create a 6 character string that is the origin & destination city pair. Create all the possible…arrow_forward
- #include <bits/stdc++.h>using namespace std;int main() { double matrix[4][3]={{2.5,3.2,6.0},{5.5, 7.5, 12.6},{11.25, 16.85, 13.45},{8.75, 35.65, 19.45}}; cout<<"Input no in first row of matrix"<<endl; for(int i=0;i<3;i++){ double t; cin>>t; matrix[0][i]=t; } cout<<"Contents of the last column in matrix"<<endl; for(int i=0;i<4;i++){ cout<<matrix[i][2]<<" "; } cout<<"Content of first row and last column element in matrix is: "<<matrix[0][3]<<endl; matrix[3][2]=13.6; cout<<"Updated matrix is :"<<endl; for(int i=0;i<4;i++){ for(int j=0;j<3;j++){ cout<<matrix[i][j]<<" "; }cout<<endl; } return 0;} Please explain this codearrow_forward#include <stdio.h> struct Single { int num; }; void printSingle(int f) { int binaryNum[33]; int i = 0; while(f>0) { binaryNum[i] = f % 2; f = f/2; i++; } for (int j=i-1; j>= 0; j--) { printf("%d",binaryNum[j]); } } int main() { struct Single single; single.num = 33; printf("Number: %d\n",single.num); printSingle(single.num); return 0; }arrow_forwardC++ Program: #include <iostream>#include <string> using namespace std; const int AIRPORT_COUNT = 12;string airports[AIRPORT_COUNT] = {"DAL","ABQ","DEN","MSY","HOU","SAT","CRP","MID","OKC","OMA","MDW","LAX"}; int main(){ // define stack (or queue ) here string origin; string dest; string citypair; cout << "Loading the CONTAINER ..." << endl; // LOAD THE STACK ( or queue) HERE // Create all the possible Airport combinations that could exist from the list provided. // i.e DALABQ, DALDEN, ...., ABQDAL, ABQDEN ... // DO NOT Load SameSame - DALDAL, ABQABQ, etc .. cout << "Getting data from the CONTAINER ..." << endl;// Retrieve data from the STACK/QUEUE here } Using the attached program (AirportCombos.cpp), create a list of strings to process and place on a STL STACK container. The provided code is meant to be generic. Using the provided 3 char airport codes, create a 6 character string that is the origin &…arrow_forward
- #include <stdio.h>#include <stdlib.h>#include <time.h> struct treeNode { struct treeNode *leftPtr; int data; struct treeNode *rightPtr;}; typedef struct treeNode TreeNode;typedef TreeNode *TreeNodePtr; void insertNode(TreeNodePtr *treePtr, int value);void inOrder(TreeNodePtr treePtr);void preOrder(TreeNodePtr treePtr);void postOrder(TreeNodePtr treePtr); int main(void) { TreeNodePtr rootPtr = NULL; srand(time(NULL)); puts("The numbers being placed in the tree are:"); for (unsigned int i = 1; i <= 10; ++i) { int item = rand() % 15; printf("%3d", item); insertNode(&rootPtr, item); } puts("\n\nThe preOrder traversal is: "); preOrder(rootPtr); puts("\n\nThe inOrder traversal is: "); inOrder(rootPtr); puts("\n\nThe postOrder traversal is: "); postOrder(rootPtr);} void insertNode(TreeNodePtr *treePtr, int value) { if (*treePtr == NULL) { *treePtr = malloc(sizeof(TreeNode)); if (*treePtr != NULL) { (*treePtr)->data = value;…arrow_forward2. int count(1); while(count <5) { } --count; std::cout << count << endl; Maalarrow_forwarduse c++ Programming language Write a program that creates a two dimensional array initialized with test data. Use any data type you wish . The program should have following functions: .getAverage: This function should accept a two dimensional array as its argument and return the average of each row (each student have their average) and each column (class test average) all the values in the array. .getRowTotal: This function should accept a two dimensional array as its first argument and an integer as its second argument. The second argument should be the subscript of a row in the array. The function should return the total of the values in the specified row. .getColumnTotal: This function should accept a two dimensional array as its first argument and an integer as its second argument. The second argument should be the subscript of a column in the array. The function should return the total of the values in the specified column. .getHighestInRow: This function should accept a two…arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY