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

I need help with part of a program for a homework assignment. For time sake, I\'

ID: 3569467 • Letter: I

Question

I need help with part of a program for a homework assignment. For time sake, I'm posting just the part I need help with...

Given two text files - one called query and one called template, each containing data in the form of doubles. The query file contains 1 set of data and the template file contains 137 sets of data. The query file has 5,600 elements and each template set contains 5,600 elements. I need to calculate the dot product of the query file and each of the 137 template data sets. So, I would have to calculate the dot product 137 times. Can someone help me write the part of the program, in C++, that gets the data from the text files and calculate the dot product? Eventually, I need to implement a quicksort method to output the top 10 values by index number, but if I can get help with the file i/o part, that would be of great help.

If you can help me even further, I will give more points. Thanks.

Explanation / Answer

#include<stdio.h>

#define M 50

struct state {

  char name[50];

  long int population;

  float literacyRate;

  float income;

} st[M]; /* array of structure */

int main() {

  int i, n, ml, mi, maximumLiteracyRate, maximumIncome;

  float rate;

  ml = mi = -1;

  maximumLiteracyRate = maximumIncome = 0;

  printf("Enter how many states:");

  scanf("%d", &n);

  for (i = 0; i < n; i++) {

     printf(" Enter state %d details :", i);

     printf(" Enter state name : ");

     scanf("%s", &st[i].name);

     printf(" Enter total population : ");

     scanf("%ld", &st[i].population);

     printf(" Enter total literary rate : ");

     scanf("%f", &rate);

     st[i].literacyRate = rate;

     printf(" Enter total income : ");

     scanf("%f", &st[i].income);

  }

  for (i = 0; i < n; i++) {

     if (st[i].literacyRate >= maximumLiteracyRate) {

       maximumLiteracyRate = st[i].literacyRate;

       ml++;

     }

     if (st[i].income > maximumIncome) {

       maximumIncome = st[i].income;

       mi++;

     }

  }

  printf(" State with highest literary rate :%s", st[ml].name);

  printf(" State with highest income :%s", st[mi].name);

  return (0);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote