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...
part1 7.4 Create a new file (in Dev C++) and save it Write a program that uses parallel arrays to store payroll data for 5 employees. The program should display each employee name and then prompt for hours and rate. Calculate and store gross pay for each employee. After the data has been entered for all employees, display each employee's ID, name, hours, rate and gross pay as a table. Use the following arrays: arrEmpIDs: array of five integers, initialized...
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...
C++ programming language Write a program that asks the user for a file name. The file contains a series of scores(integers), each written on a separate line. The program should read the contents of the file into an array and then display the following content: 1) The scores in rows of 10 scores and in sorted in descending order. 2) The lowest score in the array 3) The highest score in the array 4) The total number of scores in...
Write a program that allows the user to navigate the lines of text in a file. The program should prompt the user for a filename and input the lines of text into a list. The program then enters a loop in which it prints the number of lines in the file and prompts the user for a line number. Actual line numbers range from 1 to the number of lines in the file. If the input is 0, the program...
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...
Language: c++ Write a program that opens a file to read 20 floating point numbers and store the information in a 4 x 5 array. The program should do the following: a. Compute the average of each set of 5 values b. Determine the largest value of the 20 values c. Report the results; print the original matrix and average of each row, and the largest of the values in this function. d. At the end of the program prompt...
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...
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...