1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
CaHeK987 [17]
2 years ago
10

I need this problem solved in C++ progamming

Computers and Technology
1 answer:
daser333 [38]2 years ago
5 0

Using the knowledge in computational language in C++ it is possible to write a code that prompt user for a file name and read the data containing information for a course, store and process the data

<h3>Writting in C++ code:</h3>

<em>#include<iostream></em>

<em>#include<cstring></em>

<em>#include<fstream></em>

<em />

<em>using namespace std;</em>

<em />

<em>struct Student{</em>

<em>string lastName,firstName;</em>

<em>char subject;</em>

<em>int marks1,marks2,marks3;</em>

<em>};</em>

<em />

<em>char calcGrade(double avg){</em>

<em>char grade;</em>

<em>if(avg>=90.0&&avg<=100.0)</em>

<em>grade='A';</em>

<em>else if(avg>=80&&avg<=89.99)</em>

<em>grade='B';</em>

<em>else if(avg>=70&&avg<=79.99)</em>

<em>grade='C';</em>

<em>else if(avg>=60&&avg<=69.99)</em>

<em>grade='D';</em>

<em>else</em>

<em>grade='E';</em>

<em>return grade;</em>

<em>}</em>

<em />

<em>int main(){</em>

<em>char inFilename[20],outFilename[20];</em>

<em>int noOfRec,i,sum,count;</em>

<em>double avg,classAvg;</em>

<em>char grade;</em>

<em>cout<<"Please enter the name of the input file: ";</em>

<em>cin>>inFilename;</em>

<em>cout<<"Please enter the name of the output file: ";</em>

<em>cin>>outFilename;</em>

<em>ifstream ifile;</em>

<em>ifile.open(inFilename);</em>

<em>ofstream ofile;</em>

<em>ofile.open(outFilename);</em>

<em>if(!ifile){</em>

<em>cout<<inFilename<<" cannot be opened";</em>

<em>return -1;</em>

<em>}else{</em>

<em>ifile>>noOfRec;</em>

<em>struct Student s[noOfRec];</em>

<em>for(i=0;i<noOfRec;i++){</em>

<em>ifile>>s[i].lastName,s[i].firstName,s[i].subject,s[i].marks1,s[i].marks2,s[i].marks3;</em>

<em>}</em>

<em>if(!ofile){</em>

<em>cout<<outFilename<<" cannot be opened";</em>

<em>}else{</em>

<em>ofile<<"Student Grade Summary\n";</em>

<em>ofile<<"---------------------\n";</em>

<em>ofile<<"ENGLISH CLASS\n";</em>

<em>ofile<<"Student name\tTest Avg\n";</em>

<em>sum=0;</em>

<em>count=0;</em>

<em>classAvg=0.0;</em>

<em>for(i=0;i<noOfRec;i++){</em>

<em>if(s[i].subject=='E'){</em>

<em>avg=(s[i].marks1+s[i].marks2+s[i].marks3)/3;</em>

<em>grade=calcGrade(avg);</em>

<em>ofile<<s[i].firstName<<" "<<s[i].lastName<<"\t"<<avg<<"\t"<<grade<<"\n";</em>

<em>sum+=avg;</em>

<em>count+=1;</em>

<em>}</em>

<em>}</em>

<em>classAvg=sum/count;</em>

<em>ofile<<"\n\t\tClass Average\t\t"<<classAvg<<"\n";</em>

<em>ofile<<"---------------------\n\n";</em>

<em>ofile<<"HISTORY CLASS\n";</em>

<em>ofile<<"Student name\tTest Avg\n";</em>

<em>sum=0;</em>

<em>count=0;</em>

<em>classAvg=0.0;</em>

<em>for(i=0;i<noOfRec;i++){</em>

<em>if(s[i].subject=='H'){</em>

<em>avg=(s[i].marks1+s[i].marks2+s[i].marks3)/3;</em>

<em>grade=calcGrade(avg);</em>

<em>ofile<<s[i].firstName<<" "<<s[i].lastName<<"\t"<<avg<<"\t"<<grade<<"\n";</em>

<em>sum+=avg;</em>

<em>count+=1;</em>

<em>}</em>

<em>}</em>

<em>classAvg=sum/count;</em>

<em>ofile<<"\n\t\tClass Average\t\t"<<classAvg<<"\n";</em>

<em>ofile<<"---------------------\n\n";</em>

<em>ofile<<"MATH CLASS\n";</em>

<em>ofile<<"Student name\tTest Avg\n";</em>

<em>sum=0;</em>

<em>count=0;</em>

<em>classAvg=0.0;</em>

<em>for(i=0;i<noOfRec;i++){</em>

<em>if(s[i].subject=='M'){</em>

<em>avg=(s[i].marks1+s[i].marks2+s[i].marks3)/3;</em>

<em>grade=calcGrade(avg);</em>

<em>ofile<<s[i].firstName<<" "<<s[i].lastName<<"\t"<<avg<<"\t"<<grade<<"\n";</em>

<em>sum+=avg;</em>

<em>count+=1;</em>

<em>}</em>

<em>}</em>

<em>classAvg=sum/count;</em>

<em>ofile<<"\n\t\tClass Average\t\t"<<classAvg<<"\n";</em>

<em>ofile<<"---------------------\n\n";</em>

<em>ifile.close();</em>

<em>ofile.close();</em>

<em>}</em>

<em>}</em>

See more about C++ code at brainly.com/question/19705654

#SPJ1

You might be interested in
Scripting languages are unique computer languages with a specialized function. explain what scripting languages do, and how this
yarga [219]

Scripting languages are unique computer languages because they automate task that could be done by human operator and are easy to use.

<h3>What is a scripting language?</h3>

Scripting languages are programming languages that is interpreted.

They are programming languages that automates the task that will originally be performed by a human operator.

Scripting languages are used to give instruction to other software to run accordingly to how you want it.

The scripting language is different form other language base on the fact that its interpreted . This means the code are translated to machine code when it is run.

The major advantage of scripting languages is that it is human readable and understandable.

Examples of scripting languages are Python and JavaScript.

learn more on scripting here: brainly.com/question/12763341

#SPJ1

3 0
2 years ago
To copy consecutive items, click the first item in the group, hold down _______, and click the last item
Nikitich [7]
C. Shift , you can control click to select one at a time
7 0
3 years ago
Read 2 more answers
How can you create balance to your drawing using only grayscale values?
Leokris [45]

use only fine pencils  

5 0
4 years ago
Which internet explorer 11 feature enables it to correctly display pages that were developed using older technologies?
DedPeter [7]
The Internet Explorer 11 feature that enables you to do that is known as the compatibility view.
It means that this browser will make the pages developed using older technologies compatible with the new technologies, so that you can see them even though they were made in such different ways. Microsoft Word also has this option to view documents made using an older version of Microsoft Office.
5 0
4 years ago
The ____ command is used to disconnect a datatable object from the database. (
lisabon 2012 [21]
The delete from command I think
7 0
3 years ago
Read 2 more answers
Other questions:
  • Which of the following makes videos appear smoother and more fluid?
    9·2 answers
  • ________ software helps run the computer and coordinates instructions between other software and the hardware devices.
    7·1 answer
  • There are two different perspectives in terms of how programs are delivered for different ethnic groups. If an agency offers dif
    14·1 answer
  • Sometimes your Internet is slow and sluggish, what are some common problems that affect network functionality. Check all that ap
    14·1 answer
  • The __ contains the computers “brain,” the central processing unit (cpu)
    9·1 answer
  • Design a class FileArray that has a static method named writeArray. The method should take two arguments: the name of a file and
    11·1 answer
  • Why is printer an output device​
    14·2 answers
  • All the following are the basis of the World Wide Web except:
    14·2 answers
  • Why do we need to know the different Networking Devices?​
    10·1 answer
  • A market-product strategy that requires no change in the basic product but instead seeks new buyers is known as ______
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!