
Concept explainers
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//structure
typedef struct
{
char Username [20];
int cents;
}
value;
int *coin Change (int change);
//main function
int main ()
{
FILE *f;
//open the file
f = f open ("coins.txt", "r");
//check if file not opened
if(f==NULL)
{
printf ("File not opened!");
return 1;
}
value arr [10];
int i, j, n, option, totalCoins;
char name [20];
int *coins; // =
//read the file
for (i=0;!feof(f) ; i++)
{
fscanf(f, "%s", arr[i].Username);
fscanf(f, "%d", &arr[i].cents);
}
n = i;
//close the file
fclose(f);
//loop
while (1)
{
//display menu
printf ("1. Enter name\n");
printf ("2. Exit\n\n");
//prompt and read option
printf ("Enter option (1 or 2): ");
scanf ("%d", &option);
//switch statement
switch(option)
{
case 1:
//read the name
scanf ("%s", name);
totalCoins = 0;
//search in the list
for(i=0; i<n; i++)
{
if(!strcmp(name, arr[i].Username))
{
totalCoins = totalCoins + arr[i].cents;
}
}
//check if not found
if(totalCoins==0)
printf("Not found\n\n");
else
{
//get the change
coins = coinChange(totalCoins);
//print the change
if(coins[0])
printf("50 cents: %d\n", coins[0]);
if(coins[1])
printf("20 cents: %d\n", coins[1]);
if(coins[2])
printf("10 cents: %d\n", coins[2]);
if(coins[3])
printf("5 cents: %d\n", coins[3]);
printf("\n\n");
}
break;
case 2:
//create csv file
f = fopen ("change.csv", "w");
//search the name in the list
for(i=0; i<n-1; i++)
{
totalCoins = arr[i].cents;
strcpy(name, arr[i].Username);
for(j=i+1; j<n; j++)
{
if(!strcmp(name, arr[j].Username))
{
totalCoins = totalCoins + arr[j].cents;
arr[j].cents = 0;
}
}
//check if found
if(totalCoins!=0)
{
//get change
coins = coinChange(totalCoins);
//print to the csv file
fprintf(f, "%s,%d,%d,%d,%d,%d\n", arr[i].Username, totalCoins, coins[0],
coins[1],coins[2],coins[3]);
}
}
//close the file
fclose(f);
return 0;
default:
printf ("Wrong option. Try again\n\n");
}
}
return (0);
}
//function to calculate the change
int* coinChange (int change)
{
int *coins = (int*) calloc (4, sizeof(int));
While (change > 0)
{
if (change > 0 && change <=95 && change% 5 == 0)
{
if (change >= 50)
{
change -= 50;
coins [0] ++;
}
else if (change >= 20)
{
change -= 20;
coins [1] ++;
}
else if(change>=10)
{
change -= 10;
coins [2] ++;
}
else if(change>=5)
{
change -= 5;
coins [3] ++;
}
}
}
return coins;
}

Step by stepSolved in 2 steps

- # dates and times with lubridateinstall.packages("nycflights13") library(tidyverse)library(lubridate)library(nycflights13) Qustion: Create a function called date_quarter that accepts any vector of dates as its input and then returns the corresponding quarter for each date Examples: “2019-01-01” should return “Q1” “2011-05-23” should return “Q2” “1978-09-30” should return “Q3” Etc. Use the flight's data set from the nycflights13 package to test your function by creating a new column called quarter using mutate()arrow_forward#include <iostream> #include <iomanip> #include <string> #include <vector> using namespace std; class Movie { private: string title = ""; int year = 0; public: void set_title(string title_param); string get_title() const; // "const" safeguards class variable changes within function string get_title_upper() const; void set_year(int year_param); int get_year() const; }; // NOTICE: Class declaration ends with semicolon! void Movie::set_title(string title_param) { title = title_param; } string Movie::get_title() const { return title; } string Movie::get_title_upper() const { string title_upper; for (char c : title) { title_upper.push_back(toupper(c)); } return title_upper; } void Movie::set_year(int year_param) { year = year_param; } int Movie::get_year() const { return year; } int main() { cout << "The Movie List program\n\n"…arrow_forwardC++ help with this fixing code .cpp file #include<iostream>#include<string>#include<vector>#include"Food.h"using namespace std; class Nutrition{ private: string name; double Calories double Fat double Sugars double Protein double Sodium Nutrition(string n, double c, double f, double s, double p, double S): name(n), Calories(c), Fat(f),Sugars(s), Protein(p),Sodium(S){} food[Calories]= food[Fat]=food[Sugars]=food[Protein]=food[Sodium]=0; name = "";} Nutrition(string type, double calories, double fat, double sugar,double protein, double sodium){ food[Calories]= calories; food[Fat]=fat; food[Sugars]= sugar; food[Protein]=protein; food[Sodium]=sodium; name= type; } void setName(string type){ name = type; } void setCalories(double calories){ food [Calories]= calories; } void setFat(double fat){ food [Fat]= fat; } void setSugars(double sugar){ food [Sugars]= sugar; } void setProtein(double protein){ food [Protein]= protein; } void…arrow_forward
- Game of Hunt in C++ language Create the 'Game of Hunt'. The computer ‘hides’ the treasure at a random location in a 10x10 matrix. The user guesses the location by entering a row and column values. The game ends when the user locates the treasure or the treasure value is less than or equal to zero. Guesses in the wrong location will provide clues such as a compass direction or number of squares horizontally or vertically to the treasure. Using the random number generator, display one of the following in the board where the player made their guess: U# Treasure is up ‘#’ on the vertical axis (where # represents an integer number). D# Treasure is down ‘#’ on the vertical axis (where # represents an integer number) || Treasure is in this row, not up or down from the guess location. -> Treasure is to the right. <- Treasure is to the left. -- Treasure is in the same column, not left or right. +$ Adds $50 to treasure and no $50 turn loss. -$ Subtracts…arrow_forwardstruct employee{int ID;char name[30];int age;float salary;}; (A) Using the given structure, Help me with a C program that asks for ten employees’ name, ID, age and salary from the user. Then, it writes the data in a file named out.txt (B) For the same structure, read the contents of the file out.txt and print the name of the highest salaried employee and youngest employee names name in the outputscreen.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





