I have this two parts quistion that I would like an answer for. Than you Part1:
ID: 3810085 • Letter: I
Question
I have this two parts quistion that I would like an answer for.
Than you
Part1:
Write a program that performs the following:
Presents the user a menu where they choose between:Add a new student to the class
Prompts for first name, last name
If assignments already exist, ask user for new student’s scores to assignments
Assign grades for a new assignment
If students already exist, prompt user with student name, ask them for score
Students created after assignment will need to have score provided
List one student, displaying all their grades and their course average
Prompt user for student, telling them which inputs are valid
If no students and/or no assignments, tell user to try after data input
List all the scores for a chosen assignment
Prompt user for assignment, telling them which options are valid
includes class average
if no valid assignments and/or students, tell user to try after data input
Display all grades currently contained in the gradebook
If no students, tell user gradebook is empty
Exit the program
Return to step 1
For your program you will be using an array (size: 10 elements) of the Student struct, which contains First Name, Last Name (char arrays or strings), and 10 assignment scores (double). Keep track the number of students and number of assignments with variables (might need to pass them to functions as arguments). If the user tries to add students or assignments when they are already full, they should get an error message.
Input should accept either a single lowercase char or an integer, prompts should tell user what to enter.
Points:
2 - Documentation, readability, format
2 - Filename and Header
2 - Output testing
2 - Proper program flow (conditions, loops, functions, etc)
2 - Proper use of structs
Header
//Author: Mehdi Peiravi (your name)
//CPSC 121 Lab 5
//<MM/DD/YY> (Current Date)
Filename
<Last Name><First Initial>lab5.cpp
For example, my assignment would be named MayElab5.cpp
-----------------------------
part2:
We want to enable the user to load data in from a file named “scores.txt” when they’re starting the program, or allow them to proceed with no students or assignments.
At the menu, we also want to give the user the option at the menu to save the data currently stored in the array to a file named “scores.txt”
scores.txt format:
4//Number of students
3//Number of assignments
Hannah Montana 83.6 79.4 91.3//One student per following line
Joe Bigsworth 90.0 0 83.5
Oberyn Martell 95.4 84.3 73.9
Ned Stark 79.8 86.5 91.3
Points:
2 - File output
2 - File input
2 - Documentation, readability, format
2 - Filename and Header
2 - Proper program flow (conditions, loops, functions, etc)
2 - Output Testing
2 - Proper use of structs
Header
//Author: Mehdi Peiravi (your name)
//CPSC 121 Lab 5
//<MM/DD/YY> (Current Date)
Filename
<Last Name><First Initial>lab5.cpp
For example, my assignment would be named MayElab5.cpp
Thank You.
Explanation / Answer
#include<iostream.h>//include the necssary header files for the program.
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
struct student
{
int rollno; //to store the student roll number
string name[]; //to store the student name;
double Ass_scores[10]; //to store the assesment scores.
} s[10];
void main()
{
int c;
cout << "Enter information of students: " << endl; //here the student is to diplay a list of choices.
cout <<"---------------------------------"<< endl;
cout << "Enter 1.To Insert student record: " << endl;//this is to insert the student record.
cout << "Enter 2.To Display student information: " << endl;//this is to display a student information.
getline(cin,c); //here the student entered input is stored in and processed.
switch(c)
{
case 1: //if the user entered 1 then the following can be done.
cout<<"Enter the student Roll number:"<<endl;
cin>>s[i].rollno;
cout<<"Enter the student First name:"<<endl;
cout<<"Enter the student last name:"<<endl;
cin>>s[i].name;
cout<<"Enter the ten subject assignment marks:"<<endl
cin>>s[i].Ass_scores;
break;
case 2:
cout<<"Enter the roll number you want to display the information."<<endl;
int rno; //here the student entered input is to read and store in a temporary variable.
cin>>rno;
int flag=0;
if(s[i].rollno == rno) //here the entered roll number is matched.
{
flag = 1;
cout<<"Student Data: ";
cout<<"Student No: "<<s[i].rollno;
cout<<" Name: "<<s[i].name;
cout<<"scores are:"<<s[i].Ass_scores;
break;
}
}
if(!flag)
{
cout<<" Sorry..!!..Student Record not Found.!! ";
getch();
exit(1);
}
default:cout<<"You have entered a wrong choice.";
break;
}
2.
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream.h>
void main()
{
using namespace std;
ifstream file("scores.txt");//if the files is opened successfully then it will insert the data.to the struct.
if(file.is_open())
{
struct student
{ int rollno;
string name[];
double Ass_scores[3];
} s[10];
for(int i = 0; i < 10; ++i)
{
file >> s[i];
}
}
else //if the text file failed to open then it will display an error that the file failed to open.
{
cout<<"failed to read file"<<endl;
}
}