In this assignment, you will write two different programs, so you will need two different file. They will be named abc1234_HW8_1.c and abc1234_HW8_2.c. Both will have everything done in main.
In file abc1234_HW_1.c:
You will be creating and saving a grade book to a file. This will do the following:
In file abc_1234_HW8_2:
This will be the receipt problem from HW7, except all prices and codes will be stored in a file. You will need to do the following:
CS131_HW8_data1.txt
10
1345 22.35
1351 44.56
533 458.00
147 55.29
14 4.00
342 9.24
24 8.88
2829 92.50
219 0.25
3278 4.58
CSE1310_HW8_data2.txt
15
1345 22.35
1351 44.56
533 458.00
147 55.29
14 4.00
342 9.24
24 8.88
2829 92.50
219 0.25
3278 4.58
785 20.00
888 42.89
5 9.99
25 8.78
62 150.00
nxt2364_HW7.c
#include < stdbool.h >
#include < stdio.h >
#include < stdio.h >
// A.
bool checkDuplicates(int arr[], int n, int k)
{
for (int i = 0; i < n; i++) {
int j = i + 1;
int range = k;
while (range > 0 && j < n) {
if (arr[i] == arr[j])
return true;
j++;
range--;
}
}
return false;
}
// B.
void white_black(int pixels[][5], int rows){
int r, c;
for(r=0; r<5; r++){
for(c=0; c<5; c++){
pixels[r][c] = 255 - pixels[r][c];
}
}
for(r=0; r<5; r++){
for(c=0; c<5; c++){
printf("%4d",pixels[r][c]);
}
printf("\n");
}
}
int main()
{
// A.
int arr[10];
for(int i = 0; i< 10; ++i) {
printf("Input number %d:",i+1);
scanf("%d", &arr[i]);
}
int n = sizeof(arr) / sizeof(arr[0]);
if (checkDuplicates(arr, n, 3))
printf("There are duplicate values \n");
else
printf("There are not duplicate values \n");
printf("----------- \n");
// B.
int pix[5][5] = {
{183, 226, 180, 117, 222},
{193, 188, 0, 124, 52},
{46, 157, 214, 49, 246},
{1, 78, 167, 143, 204},
{98, 175, 159, 152, 248}
};
white_black(pix,5);
printf("----------- \n");
// C.
int UPC[10];
float price[10];
float Total=0;
for(int i = 0; i<10; ++i) {
printf("Enter UPC #%d:",i+1);
scanf("%d", &UPC[i]);
printf("Enter price #%d:",i+1);
scanf("%f", &price[i]);
Total = Total + price[i];
}
printf("Item ");
printf("Code ");
printf("Price \n");
for(int i=0; i<10; i++) {
printf("%d ",UPC[i]);
printf(" ");
printf("%.2f ",price[i]);
printf("\n");
}
printf("Total ");
printf(" ");
printf("%.2f ",Total);
}