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:

  • Ask the user for the number of students and store it
  • Ask the user for the number of grades per student and store it
  • Create arrays to hold student id numbers and grades
  • For each student, ask the user for that student's student id and store them
  • For each grade for each student, ask the user for that student's grade and store them
  • Create and open a file where the student ids and names to a stored titled "abc1234_grades.txt"
  • On the first row, write the number of students.
  • On the second row, write the number of grades.
  • For each row after, use the following format:
    • Student_id grade1 grade2 grade3 grade4 ... grade n average (2 decimal places)
  • Close the file

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:

  • Get the name of the file from the command line arguments.
  • Open the file
  • Read in the first value, representing how many items there are in the list.
  • Create your item code array
  • Create your price array
  • Read in the codes and prices into their arrays.
  • Close the file
  • Assume the user is going to check out 10 items
  • For each item
    • Ask the user to enter the item code (assume user is only going to enter item codes from the list)
    • Find the corresponding price in the array.
    • Store these values in the arrays to generate the receipt
  • Print out the receipt, just like in homework 7.
  • If item is not in the list, ask for the price, update the arrays and the file to include the added item

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);
}
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.