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

Scenario: You are given an input file, cpts121.txt, which contains an instructor

ID: 3917392 • Letter: S

Question

Scenario: You are given an input file, cpts121.txt, which contains an instructor name and a listing of students and their associated data: Name, Student ID, GPA, and Major. Example input file: Daniel Olivares Bob Smith 1231234 3.78 Computer Science Margaret Bailey 1231235 3.33 Mathematics John Morgan 1231236 2.1 Computer Science The first line of the file is the instructor name name (Daniel Olivares in the example file above). You are guaranteed the name will be less than or equal to 50 characters. The remainder of the file contains information about a variable number of students. You are guaranteed the number of students will be less than or equal to 100. You do not have to use dynamic memory allocation or linked lists, though you are welcome to do so if you wish. Define a structure called students_t that contains data components for the student information fields above. Read in the package information in cpts121.txt into an array of students_t structures. Display the student information in forward order and statistics about the students. Make sure to use appropriate data types! Given this input data you should be able to: A. Create a menu with integer choices (e.g. 1-6) to control the following: 1. Read data in from a file to populate that array of structs with data 2. Print out a summary of the data to the console window (iteratively) 3. Print out a summary of the data to the console window (recursively) 4. Write the summary of the data to an output file. 5. Calculate and print statistics based on the input data, e.g. max-min-average-counts-etc. to the console window. 6. Write the student information and statistics to an output file. B. Validate user input in your menu (e.g. ‘exit’ is not a valid choice and should not cause an infinite loop). C. Validate variable values before processing menu selections (e.g. you can’t read contents from a file before opening the file!) D. Be able to handle an UNKNOWN number of student data from the input file. (Tip: solve for a FIXED number of data and then solve for unknown). E. Convert your program to use linked lists instead of arrays to store your data. Tip: Complete the task without the menu portion first and then worry about the menu after handling the rest. Alternately, use the menu from the Lab 12-1 starter code as your menu and modify it to match this task!

USE C++ TO CODE

Task 3: "Practice Lab Exam" Scenario: You are given an input file, cpts121.txt, which contains an instructor name and a listing of students and their associated data: Name, Student ID, GPA, and Major Example input file Daniel Olivares Bob Smith 1231234 3.78 Computer Science Margaret Bailey 1231235 3.33 Mathematics John Morgan 1231236 2.1 Computer Science The first line of the file is the instructor name name (Daniel Olivares in the example file above). You are guaranteed the name will be less than or equal to 50 characters. The remainder of the file contains information about a variable number of students. You are guaranteed the number of students will be less than or equal to 100. You do not have to use dynamic memory allocation or linked lists, though you are welcome to do so if you wish. Define a structure called students t that contains data components for the student information fields above. Read in the package information in cpts121.txt into an array of students_t structures. Display the student information in forward order and statistics about the students. Make sure to use appropriate data types Given this input data you should be able to: A. Create a menu with integer choices (e.g. 1-6) to control the following: 1. Read data in from a file to populate that array of structs with data 2. Print out a summary of the data to the console window (iteratively) 3. Print out a summary of the data to the console window (recursively) 4. Write the summary of the data to an output file 5. Calculate and print statistics based on the input data, e.g. max-min-average-counts-etc. to the console window Write the student information and statistics to an output file 6. B. Validate user input in your menu (e.g. 'exit' is not a valid choice and should not cause an infinite C. D. E. loop) Validate variable values before processing menu selections (e.g. you can't read contents from a file before opening the filel) Be able to handle an UNKNOWN number of student data from the input file. (Tip: solve for a FIXED number o data and then solve for unknown) Convert your program to use linked lists instead of arrays to store your data Tip: Complete the task without the menu portion first and then worry about the menu after handling the rest. Alternately, use the menu from the Lab 12-1 starter code as your menu and modify it to match this task!

Explanation / Answer

here is your file : --------->>>>>>>>>

#include<iostream>
#include<fstream>
#define MAX 100

using namespace std;

typedef struct student{
string name;
long int id;
double gpa;
string major;
}students_t;

void readFile(students_t students[MAX],int &size,string &profName){
ifstream ifs;
ifs.open("cpts121.txt");
if(!ifs.is_open()){
  cout<<" Input File Not Found !!! ";
  return;
}
getline(ifs,profName);
size = 0;
while(!ifs.eof()){
  getline(ifs,students[size].name);
  if(ifs.eof() || size >= MAX){
   break;
  }
  ifs>>students[size].id>>students[size].gpa;
  getline(ifs,students[size].major);
  getline(ifs,students[size].major);
  size++;
}
ifs.close();
}

void print(students_t st,ostream &ous){
ous<<endl<<"Name:- "<<st.name<<endl;
ous<<"Id:- "<<st.id<<endl;
ous<<"GPA:- "<<st.gpa<<endl;
ous<<"Major:- "<<st.major<<endl;
}

void printIterative(students_t students[MAX],int size,ostream &ous){
for(int i = 0;i<size;i++){
  print(students[i],ous);
}
}

void printRecursive(students_t students[MAX],int i,int size,ostream &ous){
if(i >= size)
  return;
print(students[i],ous);
printRecursive(students,i+1,size,ous);
}

void calculatePrintStatistic(students_t sts[MAX],int size,ostream &ous){
double avg,max,min;
max = sts[0].gpa;
min = sts[0].gpa;
ous<<endl<<"Number Of Students:- "<<size<<endl;
for(int i = 0;i<size;i++){
  avg += sts[i].gpa;
  if(max < sts[i].gpa){
   max = sts[i].gpa;
  }
  
  if(min > sts[i].gpa){
   min = sts[i].gpa;
  }
}

ous<<"Maximum GPA:- "<<max<<endl;
ous<<"Minimum GPA:- "<<min<<endl;
ous<<"Average GPA:- "<<(avg/size)<<endl;
}

void menu(){
cout<<" 1- Read Data From File ";
cout<<" 2- Summary Iteratively";
cout<<" 3- Summary Recursively";
cout<<" 4- Summary to output file";
cout<<" 5- Print Statistics on console";
cout<<" 6- Write Student info and Statistics to output file";
cout<<" 7- Exit";
cout<<" Choose : ";
}

int main(){
ofstream ofs;
string choice = "0";
students_t students[MAX];
int size = 0;
string profName;
while(choice[0] != '7'){
  menu();
  getline(cin,choice);
  switch(choice[0]){
   case '1':readFile(students,size,profName);break;
   case '2':printIterative(students,size,cout);break;
   case '3':printRecursive(students,0,size,cout);break;
   case '4':
    {
     string file;
     cout<<" Enter Output File Name : ";
     getline(cin,file);
     ofs.open(file.c_str());
     if(ofs.is_open()){
      printIterative(students,size,ofs);
     }else{
      cout<<" File opening Error !!! ";
     }
     ofs.close();
     break;
    }
   case '5':calculatePrintStatistic(students,size,cout);break;
   case '6':
    {
     string file;
     cout<<" Enter Output File Name : ";
     getline(cin,file);
     ofs.open(file.c_str());
     if(ofs.is_open()){
      printIterative(students,size,ofs);
      calculatePrintStatistic(students,size,ofs);
     }else{
      cout<<" File opening Error !!! ";
     }
     ofs.close();
     break;
    }
   case '7':break;
   default:
    cout<<" Invalid Input"<<choice<<endl;
  }
}
}

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