Answered You can hire a professional tutor to get the answer.

QUESTION

my code is giving me 16 errors on c++ i need it to be fixed #include lt;fstream.hgt; #include lt;iostream.hgt; #include lt;iomanip.hgt;...

my code is giving me 16 errors on c++ i need it to be fixed

#include <fstream.h>

#include <iostream.h>

#include <iomanip.h>

#include <conio.h>

#include <math.h>

#include <string.h>

int sumofarray(int a[50], int c);

int maxofarray(int a1[50], int c1);

char * con(const char * first, const char * second);

void main()

{

 char lastname1[256], ch, lastname[256], *c;

 int array1[50], i, j, k, temp = 0, max, user = 0, count = 0;

 double avg, sum1, SIZE;

 ofstream inFile;

 clrscr();

 while (user == 0)

 {

  temp = 0;

  while (temp == 0)

  {

   cout << "Input filename: ";

   cin >> lastname1;

   c = con(lastname1, ".txt");

   cout << "Input the Size of array =: ";

   cin >> SIZE;

   if (SIZE<0 || SIZE>50)

    cout << "Please Enter the Positive value of Size between 1 to 50";

   else

    temp = 1;

  }

  cout << "Please Enter " << SIZE << " Numbers into array." << endl << endl;

  for (i = 0; i<SIZE; i++)

  {

   cout << "Please Enter " << i + 1 << " Number into array==>";

   cin >> array1[i];

   cout << endl;

  }

  sum1 = sumofarray(array1, SIZE);

  avg = (sum1 / SIZE);

  cout << "The average is= " << avg;

  max = maxofarray(array1, SIZE);

  cout << "The maximum no is= " << max << endl;

  inFile.open(c, ios::in);

  inFile << "The values in the array is " << endl << endl;

  for (i = 0; i<SIZE; i++)

  {

   inFile << i + 1 << " element is=> " << array1[i] << endl;

  }

  inFile << " The sum of array is => " << sum1 << endl;

  inFile << " The average of array is => " << avg << endl;

  inFile << " The maximum element of array is => " << max << endl << endl;

  inFile << "The File is genrated by " << lastname1;

  inFile.close();

  cout << "You want to continue pres 'y' for yes 'n' for no" << endl;

  cin >> ch;

  if (ch == 'y')

  {

   user = 0;

   // lastname1[256]='';

   //delete []lastname1;

   count++;

  }

  else if (ch == 'n')

   user = 1;

  else

   cout << "Plesr enter 'y' or 'n'";

 }

 // Make sure the file stream is good

 getch();

}

char * con(const char * first, const char * second) {

 int l1 = 0, l2 = 0, i;

 const char * f = first, *l = second;

 // step 1 - find lengths (you can also use strlen)

 while (*f++) ++l1;

 while (*l++) ++l2;

 char *result = new char[l1 + l2];

 // then concatenate

 for (i = 0; i < l1; i++) result[i] = first[i];

 for (i = l1; i < l1 + l2; i++) result[i] = second[i - l1];

 // finally, "cap" result with terminating null char

 result[l1 + l2] = '';

 return result;

}

int sumofarray(int b[50], int len)

{

 int sum = 0, i;

 for (i = 0; i<len; i++)

 {

  sum = sum + b[i];

 }

 return sum;

}

int maxofarray(int b[50], int len)

{

 int temp = 0, i;

 for (i = 0; i<len; i++)

 {

  if (temp <= b[i])

   temp = b[i];

 }

 return temp;

}

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question