Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

As discussed for this homework use the posted solution, two parts of the solutio

ID: 3534084 • Letter: A

Question

As discussed for this homework use the posted solution, two parts of the solution has been coded:
#include "stdafx.h"

#include <stdio.h>

/*
Megawatts

M T W T F S S
10 5 7 4 9 8 11
9 12 8 6 10 5 10
8 5 10 7 9 3 12
11 9 13 4 8 9 9
9 6 9 6 7 7 8
10 5 10 4 8 6 12
12 8 7 5 6 6 10
10 10 9 8 9 8 13

Find total monthly power consumption
Find avg consumption within 8 month data
Find which day of the week has highest consumption.
*/

const int MaxRows = 8;
const int MaxColumns = 7;

void LoadData(FILE* dataFile, int powerData[MaxRows][MaxColumns]);
void PrintMonthlyPower(int powerData[MaxRows][MaxColumns]);
void HightConsumptionDay(int powerData[MaxRows][MaxColumns]);

int main()
{
FILE* dataFile;
dataFile = fopen("powerplant.txt", "r");

if (!dataFile)
{
  printf("Failed to open powerplant.txt");
  return 1;
}

int powerData[MaxRows][MaxColumns];
LoadData(dataFile, powerData);

PrintMonthlyPower(powerData);
HightConsumptionDay(powerData);
fclose(dataFile);
}

void LoadData(FILE* dataFile, int powerData[MaxRows][MaxColumns])
{
char placeHolder;

// Read first header line so that our file read pointer moves
// to the first data row. We are not using anything from header.
fscanf(dataFile, "%c %c %c %c %c %c %c", &placeHolder,
  &placeHolder, &placeHolder, &placeHolder, &placeHolder,
  &placeHolder,&placeHolder);


for(int i=0; i< MaxRows; i++)
{
  for(int j=0; j < MaxColumns; j++)
  {
   fscanf(dataFile, "%d", &powerData[i][j]);
  }
}
}

void PrintMonthlyPower(int powerData[MaxRows][MaxColumns])
{
int totalMonthyPower;
for(int i=0; i< MaxRows; i++)
{
  totalMonthyPower = 0;
  for(int j=0; j < MaxColumns; j++)
  {
   totalMonthyPower += powerData[i][j];
  }
  printf("Power consumption for month %d: %d ", i + 1, totalMonthyPower);
}
}

void HightConsumptionDay(int powerData[MaxRows][MaxColumns])
{
// Make an array of int with size 7 that can store total consumption for each day of the week.
int dailyConsumptionSum[7] = { 0 };

for(int i=0; i<MaxRows; i++)
{
  for(int j=0; j<MaxColumns; j++)
  {
   // Store total for each day in our sum array
   // We are storing within index of j as j = column = day of the week
   dailyConsumptionSum[j] += powerData[i][j];
  }
}

//Now iterate through sum to find highest consumption day
//Start by assuming first day is the highest consumption
int highestConsumptionDay = 0;
for(int i=0; i < 7; i++)
{
  if (dailyConsumptionSum[i] > dailyConsumptionSum[highestConsumptionDay])
  {
   highestConsumptionDay = i;
  }
}

// Now print the highest consumption day by switch/case to display Monday to Saturday
printf("Highest consumption day is: ");
switch(highestConsumptionDay)
{
  case 0: printf("Monday"); break;
  case 1: printf("Tuesday"); break;
  case 2: printf("Wednesday"); break;
  case 3: printf("Thursday"); break;
  case 4: printf("Friday"); break;
  case 5: printf("Saturday"); break;
  case 6: printf("Sunday"); break;
}
printf(" Total usuage: %d megawatt", dailyConsumptionSum[highestConsumptionDay]);
}


Remember to also download and save the "powerplant.txt" data file that is available within the Chapter7Data folder from Resources. Make sure your code can access the data file through correct file path. If necessary change the line fopen("....\powerplant.txt","r"); to point to right path.


Add one function to this code that can

Explanation / Answer

#include#include#includevoid main() { int cust_no, unit_con; float charge,surcharge=0, amt,total_amt; char nm[25]; clrscr(); printf("enter the customer IDNO : "); scanf("%d",&cust_no); printf(" enter the customer Name : "); scanf("%s",nm); printf(" enter the unit consumed by customer : "); scanf("%d",&unit_con); if (unit_con =200 && unit_con=400 && unit_con300) surcharge = amt*15/100.0; total_amt = amt+surcharge; if (total_amt < 25) total_amt =25; clrscr(); printf(" Electricity Bill "); printf("Customer IDNO : ]",cust_no); printf(" Customer Name : %s",nm); printf(" unit Consumed : ]",unit_con); printf(" Amount Charges @Rs. %4.2f per unit : %8.2f",charge,amt); printf(" Surchage Amount : %8.2f",surcharge); printf(" Net Amount Paid By the Customer : %8.2f",total_amt); getch();}