Question

C++ Question Write a program that will calculate a student's year marks for all his subjects.

assQ.png

Write a program that will calculate a student's year marks for all his subjects. The program must read the subject code, the assignment marks for two assignments and the percentage that each assignment contributes towards the year mark, for each subject that the student is registered for.


Create an input file called assignments.dat that contains the following information for a specific student:


The first field in each line represents the subject code, followed by the percentage that assignment 1 contributes towards the year mark and the student's mark (a percentage) for assignment 1. Then follow the percentage that assignment 2 contributes towards the year mark and the student's mark for assignment 2. You should not count the number of entries in the file to determine how many times the file must be read.


Your program must read the file line by line, calculate the student's year mark for the subject as a percentage and write the subject code and the year mark to an output file year mark.dat. If your program works correctly, the output file will look as follows:


0 2
Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #1

#include

#include


using namespace std;


int main()

{

   ifstream inputFile;

   string word;

   inputFile.open("assignment.dat");

   if(!inputFile.is_open())

      {

         cout<<"Failed to read the file.";

      }

   std::ofstream outfile;

   outfile.open("yearmark.dat", std::ofstream::trunc);

   int count = 0;

   string subject;

   int assignment1 = 1, assignment2 =1, temp;

   double percentage;

   while (inputFile >> word)

      {

         if (count == 0) {

            subject = word;

         }

         else if (count > 0 && count < 3) {

            temp = std::stoi(word);

            assignment1 = assignment1*temp;

         }

         else {

            temp = std::stoi(word);

            assignment2 = assignment2*temp;

         }

         count ++;

         if (count == 5) {

            count = 0;

            percentage = (assignment1 + assignment2)/100.0;

            outfile <<subject<<" "<<percentage<<"%"<<endl;

            assignment1 = 1;

            assignment2 = 1;

         }

      }

   

   inputFile.close();

   outfile.close();

   return 0;

}


answered by: codegates
Add a comment
Know the answer?
Add Answer to:
C++ Question Write a program that will calculate a student's year marks for all his subjects.
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • Kindly solve this using C PROGRAMMING ONLY. 4. Write a program marks.c which consists of a...

    Kindly solve this using C PROGRAMMING ONLY. 4. Write a program marks.c which consists of a main function and three other functions called. readmarks , changemarks (, and writemarks() The program begins by calling the function readmarks () to read the input file marksin. txt which consists of a series of lines containing a student ID number (an integer) and a numeric mark (a float). Once the ID numbers and marks have been read into arrays (by readmarks () the...

  • Please don't use a void fuction and this is a c++ question. Thanks Write a program...

    Please don't use a void fuction and this is a c++ question. Thanks Write a program that reads two input files whose lines are ordered by a key data field. Your program should merge these two files, writing an output file that contains all lines from both files ordered by the same key field. As an example, if two input files contain student names and grades for a particular class ordered by name, merge the information as shown below Using...

  • python question 2. In a file called passfail.py, write a Python program to solve the following...

    python question 2. In a file called passfail.py, write a Python program to solve the following problem: Given a file students.txt with the following information for a stu dent: student number, average quiz mark, average assignment mark, midterm exam mark, and final exam mark (where each mark is recorded out of 100), de termine if the student has passed or failed based on the following information: • A student will pass the course if they have a passing mark (50%...

  • C++ The programming language is c++ our program using the following data Mary Smith Green walley...

    C++ The programming language is c++ our program using the following data Mary Smith Green walley Thul Bool Gauteng ) Please key is the n ot your Ter in your mark for Mathematics Ey in your mark for use orientation Key in your mark for watory Wer in your work for Computer literacy Te in r for at e Jobs Africa School: King College 9/11 - Average Year Wark53.67 with label and code The T a QUESTION 2: (40) Suppose...

  • ONLY REQUIRE C Problem statement: You are to write a program that manages student marks for...

    ONLY REQUIRE C Problem statement: You are to write a program that manages student marks for a class. Student marks are stored as a 2D array. Each row represents the marks of one student. Each column represents one assessment. For example, if we have two students and 3 assessment items with the marks for student1 being (67.6,88.5, 75.4} and student2 being (77.5, 76.2,78.3} our 2D array would look like: 67.6, 38.5,75.4 77.5, 76.2,78.3 You are to write a script/main function...

  • using C# Write a program which calculates student grades for multiple assignments as well as the...

    using C# Write a program which calculates student grades for multiple assignments as well as the per-assignment average. The user should first input the total number of assignments. Then, the user should enter the name of a student as well as a grade for each assignment. After entering the student the user should be asked to enter "Y" if there are more students to enter or "N" if there is not ("N" by default). The user should be able to...

  • 2. In a file called passfail.py, write a Python program to solve the following problem: Given...

    2. In a file called passfail.py, write a Python program to solve the following problem: Given a file students.txt with the following information for a stu dent: student number, average quiz mark, average assignment mark, midterm exam mark, and final exam mark (where each mark is recorded out of 100), de termine if the student has passed or failed based on the following information A student will pass the course if they have a passing mark (50% or higher) for...

  • Question 5.[15 marks] [Chapters 7 and 8] Data from a random sample of a recent large second semester stage 2 statistics course (STATS 20x) were collected. Below is some information on the variabl...

    Question 5.[15 marks] [Chapters 7 and 8] Data from a random sample of a recent large second semester stage 2 statistics course (STATS 20x) were collected. Below is some information on the variables collected. Variable Grade The student's final grade for the course: A, B. C, D Pass Whether the student passed the course: Yes, No Programme The programme the student is enrolled in: BA, BCom BSc, Other Sex The student's sex: Female, Male ผhether the student regularly attended class:...

  • For each problem, you must: Write a Python program Test, debug, and execute the Python program...

    For each problem, you must: Write a Python program Test, debug, and execute the Python program Save your program in a .py file and submit your commented code to your Student Page. Note regarding comments: For every class, method or function you create, you must provide a brief description of the what the code does as well as the specific details of the interface (input and output) of the function or method. (25 pts.) Write a program that reads in...

  • C++ Write a program that reads students’ names followed by their test scores from the given...

    C++ Write a program that reads students’ names followed by their test scores from the given input file. The program should output to a file, output.txt, each student’s name followed by the test scores and the relevant grade. Student data should be stored in a struct variable of type StudentType, which has four components: studentFName and studentLName of type string, testScore of type int and grade of type char. Suppose that the class has 20 students. Use an array of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT