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

PLEASE MAKE COMMENTS AND MAKE SURE THAT THE PROGRAMS RUNS PLEASE!!!!!!!!!! PLEAS

ID: 3697228 • Letter: P

Question

PLEASE MAKE COMMENTS AND MAKE SURE THAT THE PROGRAMS RUNS PLEASE!!!!!!!!!!

PLEASE MAKE COMMENTS AND MAKE SURE THAT THE PROGRAMS RUNS PLEASE!!!!!!!!!!

4 Make sure your code can be compiled with no error prior submission. Codes which cannot be compiled will get 0 points. Problem 1: Write down a C program to collect the student's information and compute the average score of the class. The program should have following: 1) Use structure for student's information. Structure should have the fields: student name, student id, student age and student score. space for the number of students entered by user. students score. 2) Use pointers and dynamic memory allocation to allocate the 3) Write a function that should compute the average of the Note: The number of students should be input from user. Problem 2: Write down a C program that should copy the contents of an input file to a new file.

Explanation / Answer

1.STUDENT GRADE PROGRAM

#include <iostream>

#include <string>                  // For utilizing strings

using namespace std;

// Declare structure(s)

struct Student{

               string name;                          // Name of student

               int idnum;                                             // Student ID number

               int* tests;                                              // Student’s score

               double average;                     // Average of test scores

};

// Function Prototype(s)

int inputStudents();                                             // Asks user for number of students

int inputTests();                                    // Asks user for test scores

string inputName();                                             // Asks user for each student's name

int inputID();                                        // Asks user for each student's ID number

int *inputScores(int);            // Asks user for the test scores for each student

double calcAverage(int*, int);//Calculates the average score for each student

void display(Student*, int); // Displays each student's name, ID#, average //test score, and course grade

int main(){

               // Create a dynamic array of the Student structure. Array size is //based upon user input given in

               // the inputStudents function.

               Student *studentList;

               int size = inputStudents();

               studentList = new Student[size];

               // Check for possible memory allocation errors. If error is found, end program.

               if (studentList == NULL){

                               cout << "Memory Allocation Error!";

                               // system("pause");

                               return 0;

               }

               // Create a variablearray to hold the number of test scores for each student.

               int numOfTests = inputTests();

               for (int count = 0; count < size; count++){

                               studentList[count].name = inputName();

                               studentList[count].idnum = inputID();

                               studentList[count].tests = inputScores(numOfTests);

                               studentList[count].average = calcAverage(studentList[count].tests, numOfTests);

               }

               display(studentList, size);

               delete [] studentList;

               // system ("pause");

               return 0;

}

int inputStudents(){

               int students;

               cout << "How many students are there?" << endl;

               cin >> students;

               return students;

}

int inputTests(){

               int tests;

               cout << "How many tests will there be?" << endl;

               cin >> tests;

               return tests;

}

string inputName(){

               string name;

               cout << "Enter the student's name: ";

               cin >> name;

               return name;

}

int inputID(){

               int idNum;

               cout << "Enter the student's ID Number ";

               cin >> idNum;

               return idNum;

}

int *inputScores(int numOfTests){

               int *scores;

               scores = new int[numOfTests];

               cout << "Enter the test scores for the student. Press ENTER after each score." << endl;

               for (int count = 0; count < numOfTests; count++){

                               cout << "Score " << (count + 1) << ": ";

                               cin >> scores[count];

               }

               return scores;

}

double calcAverage(int *testScores, int numOfTests){

               int total = 0;

               double average;

               for (int count = 0; count < numOfTests; count++){

                               total += testScores[count];

               }

              

               average = total/numOfTests;

               return average;

}

void display(Student *studentList, int size){

               for (int count = 0; count < size; count++)

                               cout << studentList[count].name << " " << studentList[count].idnum << " "

                               << studentList[count].average << " " << endl;

               return;

}

2.FILE COPYING PROGRAM

#include<stdio.h>

#include<process.h>

void main() {

   FILE *fp1, *fp2;    //defining file pointers

   char a;

   clrscr();

   fp1 = fopen("test.txt", "r"); //opening the input file in read mode

   if (fp1 == NULL) { //if file doesnot exist inform user

      puts("cannot open this file");

      exit(1);

   }

   fp2 = fopen("test1.txt", "w"); //opening the new file in write mode

   if (fp2 == NULL) {

      puts("Not able to open this file");

      fclose(fp1);

      exit(1);

   }

   do {

      a = fgetc(fp1);   //performing a looping operation to read the input file character by character

      fputc(a, fp2);     //writing to new output file

   } while (a != EOF); //checking for end of file condition, if eof break the loop

   fcloseall();   //closing the files

   getch();

}

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