C program
(File Processing - Writing) The same Bicycle shop that contracted you to write the double array problem in HW5 has now decided that they want to keep a log of all employee transactions. Write a program that will allow users to enter in their name (you only need to use first name) and the item that they sold (for example, “James Bicycle”). After each employee types in a sale, your program should record that sale in a file called sales.txt. Each sale should comprise one line of the sales.txt file (thus, be sure to use a \n after each sale). At the end of the day when the manager types in „quit quit‟ the program should terminate.
HW5
(Two-dimension Array) A company that pays their employees on a commission basis has contracted you to write a program that will calculate how much they owe their employees. The company has 4 employees and sells 5 different products. The products and the commission each employee receives from selling the products is given below: 1. bicycle - $20 2. unicycle - $10 3. tire - $5 4. pump - $2 5. chain - $1
// question1
// this programme overwrites the file everytime it is executed
// for standard input printf,scanf etc
#include<stdio.h>
// for including bool values
#include<stdbool.h>
//for including string functionalitites
#include<string.h>
//compare whether strings are equal or not
bool stringcmp(char str1[],char str2[])
{
// len for storing current char position
int len=0;
// as long as str1 does not end keep on running
loop
while(str1[len]!='\0')
{
// as long as element of str1 is
equal to str2 keep on increasing len value for iteration
if(str1[len]==str2[len])
len++;
// break if mismatch
else
break;
}
// is str1 is parsed totally return true
if(str1[len]=='\0')
return true;
// return false if str1 as both strings are not
equal
return false;
}
int main()
{
// fp = file descriptor
FILE *fp;
// line to store line string from file
char line[20];
// open file "sales.txt" for writing
fp=fopen("sales.txt","w");
// keep on running continously
while(true)
{
// ask user for input
printf("enter name product:
");
// flush stdin to clear stdin
buffer
fflush(stdin);
// get input from stdin(keyboard)
and store in line
fgets(line,20,stdin);
// change 2nd last element to \0 as
it will be containing '\n'
line[strlen(line)-1]='\0';
// if string from input is
'exit'
if(stringcmp(line,"exit"))
{
//end loop
break;
}
// enter line to file
fprintf(fp,"%s\n",line);
}
// close file
close(fp);
return 0;
}
//answer2
#include<stdio.h>
int main()
{
//declare integer i for loop iteration , total for
calculating total commision
int i,total;
//interger variables to store total sales
int bicyle,unicycle,tire,pump,chain;
// integer 2-d array for storing values
int comm[4][5];
//read sales of each employee one by one
for(i=0;i<4;i++)
{
// ask for input for a employee and
take input from keyboard and store by rows
printf("enter employee %d
sales:\n",i+1);
printf("enter no. of bicycles:
");
scanf("%d",&comm[i][0]);
printf("enter no. of unicycles:
");
scanf("%d",&comm[i][1]);
printf("enter no. of tire:
");
scanf("%d",&comm[i][2]);
printf("enter no. of chain:
");
scanf("%d",&comm[i][3]);
printf("enter no. of pump:");
scanf("%d",&comm[i][4]);
// multiply each sales item of
employee with price of item
comm[i][0]*=20;
comm[i][1]*=10;
comm[i][2]*=5;
comm[i][3]*=1;
comm[i][4]*=2;
}
printf("\n");
// print commision of each employee
for(i=0;i<4;i++)
{
//add all the values from current
row and store in total
total=comm[i][0] + comm[i][1] +
comm[i][2] + comm[i][3] + comm[i][4];
// print total commision
printf("enter employee %d
commision: %d\n",i+1,total);
}
return 0;
}
C program (File Processing - Writing) The same Bicycle shop that contracted you to write the...
Program 7 File Processing and Arrays (100 points) Overview: For this assignment, write a program that will process monthly sales data for a small company. The data will be used to calculate total sales for each month in a year. The monthly sales totals will be needed for later processing, so it will be stored in an array. Basic Logic for main() Note: all of the functions mentioned in this logic are described below. Declare an array of 12 float/doubles...
Write a C program as follows: Single source code file Calls a function with an arbitrary name (i.e. you name it) that accepts two arrays of the same size The function should add each element in the arrays together and place the values in a third array Each array element, each array address, and the sum are printed to the screen in tabulated format with headersI also would like to request that LOTS of comments be included, as I need...
Arrays and reading from a file USE C++ to write a program that will read a file containing floating point numbers, store the numbers into an array, count how many numbers were in the file, then output the numbers in reverse order. The program should only use one array and that array should not be changed after the numbers have been read. You should assume that the file does not contain more than 100 floating point numbers. The file name...
J Inc. has a file with employee details. You are asked to write a C++ program to read the file and display the results with appropriate formatting. Read from the file a person's name, SSN, and hourly wage, the number of hours worked in a week, and his or her status and store it in appropriate vector of obiects. For the output, you must display the person's name, SSN, wage, hours worked, straight time pay, overtime pay, employee status and...
(c programming): write a program that contains a function named getName, that does not get any parameter and returns a character array of a random name from a constant list of 30 names, in a global array. the function returns that random name. each name in the list is a character string that consists of not more than 20 characters(not including finishing 0). the name consists of only characters from the american alphabet (a-zA-Z) and does not contain any "white"...
in C++ Write a program which uses the following arrays: empID: An array of 7 integers to hold employee identification numbers. The array should be initialized with the following values: 1, 2, 3, 4, 5, 6, 7. Hours: an array of seven integers to hold the number of hours worked by each employee. payRate: an array of seven doubles to hold each employee’s hourly pay rate. Wages: an array of seven doubles to hold each employee’s gross salary. The program...
Use c++ as programming language. The file needs to be created ourselves (ARRAYS) Write a program that contains the following functions: 1. A function to read integer values into a one-dimensional array of size N. 2. A function to sort a one-dimensional array of size N of integers in descending order. 3. A function to find and output the average of the values in a one dimensional array of size N of integers. 4. A function to output a one-dimensional...
JAVA Write a program that prompts the user to enter a file name, then opens the file in text mode and reads it. The input files are assumed to be in CSV format. The input files contain a list of integers on each line separated by commas. The program should read each line, sort the numbers and print the comma separated list of integers on the console. Each sorted list of integers from the same line should be printed together...
The name of the C++ file must be search.cpp Write a program that will read data from a file. The program will allow the user to specify the filename. Use a loop that will check if the file is opened correctly, otherwise display an error message and allow the user to re-enter a filename until successful. Read the values from the file and store into an integer array. The program should then prompt the user for an integer which will...