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

Write an algorithm and C++ code of your till date homework submission performanc

ID: 3800473 • Letter: W

Question

Write an algorithm and C++ code of your till date homework submission performance and output it as in the following format
firstName lastName
Class
Homework Date Status
Write homework as number as 1, 2 etc., status as submitted/notSubmitted , left aligned and also display calculation of submission percentage as (noOf Submission/totalNumberOfHomeworks)*100. Finally input firstName and lastName from a .txt file and output the above said format in a .txt file Write an algorithm and C++ code of your till date homework submission performance and output it as in the following format
firstName lastName
Class
Homework Date Status
Write homework as number as 1, 2 etc., status as submitted/notSubmitted , left aligned and also display calculation of submission percentage as (noOf Submission/totalNumberOfHomeworks)*100. Finally input firstName and lastName from a .txt file and output the above said format in a .txt file Write an algorithm and C++ code of your till date homework submission performance and output it as in the following format
firstName lastName
Class
Homework Date Status
Write homework as number as 1, 2 etc., status as submitted/notSubmitted , left aligned and also display calculation of submission percentage as (noOf Submission/totalNumberOfHomeworks)*100. Finally input firstName and lastName from a .txt file and output the above said format in a .txt file

Explanation / Answer

Here is the code for the question. The program runs by opening a file for input and anohter for output. Please change the filenames in the program as appropriate. Also specify your first name and last name in the input file. The program creates Homework objects with some dummy data. Please fill in correct details and run the program. Comments are inline.

Sample input and output is shown below. Please do rate the answer if you are happy with the program. Thanks

------

Homework.cpp

-------------

#include <iostream>
#include <fstream>
using namespace std;

//class to store homework details
class Homework
{
   int id;
   string date;
   string status;
   Homework() //default constructor
   {
       id=0;      
   }
   public:
       //constructor with parameters to initialize the object
       Homework(int n,string const &dt,string const &stat)
       {
           id=n;
           date=string(dt);
           status=string(stat);
       }
      
       //write the homework details from the object to the specified file
       void write(ostream &file)
       {
           file<<id<<" "<<date<<" "<<status<<endl;
       }
      
       //getter methods to return the date and status data members
       const string getStatus()
       {
           return status;
       }
      
       const string getDate()
       {
           return date;
       }
      
};

int main(int argc,char *argv[])
{
   //Please use correct filenames here
   string infilename="HWInput.txt",outfilename="HWOutput.txt";
   ifstream infile;
   ofstream outfile;


   //open the input and output file
   infile.open(infilename);
   outfile.open(outfilename);
   int line=0;
  
   /* if fopen( ) was not successful there was an error, so exit with error */
   if(!infile.is_open() )
   {
   cout<<"Error opening input file "<<argv[1];
   exit(1);
   }
  
   if(!outfile.is_open() )
   {
       cout<<"Error opening output file "<<argv[2];
       exit(1);
   }
  
   string fname,lname;
   //Read the first name and last name from the input file
   infile>>fname;
   infile>>lname;
  
   //Write out the first and last name to output file
   outfile<<fname<<" "<<lname<<endl;
  
   //Write the Class to output file
   outfile<<"Class X"<<endl;
  
   //Write the column names to output file
   outfile<<"Homework Date Status"<<endl;
  
   int NUMBER_OF_HOMEWORKS=8,submissions=0;
   Homework homeworks[]=
                       {
                           Homework(1,"05 Jan 2017","submitted"),
                           Homework(2,"10 Jan 2017","submitted"),
                          Homework(3,"12 Jan 2017","submitted"),
                          Homework(4,"18 Jan 2017","not submitted"),
                           Homework(5,"06 Feb 2017","submitted"),
                           Homework(6,"12 Feb 2017","not submitted"),
                           Homework(7,"18 Feb 2017","submitted"),
                           Homework(8,"25 Feb 2017","submitted")
                       };
  
                 
  
   for(int i=0;i<NUMBER_OF_HOMEWORKS;i++)
   {
       if(homeworks[i].getStatus().compare("submitted")==0)
           submissions++;
       homeworks[i].write(outfile);
   }  
  
   //calculate the percentage and write the percentage to output file
   float percentage=submissions*100.0/NUMBER_OF_HOMEWORKS;  
   outfile<<"Percentage = "<<percentage<<"%";
      
      
   //close the files
   infile.close();
   outfile.close();  
}

-------

sample HWInput.txt

------

John Smith

------

sample HWOutput.txt

------

John Smith
Class X
Homework   Date       Status
1       05 Jan 2017   submitted
2       10 Jan 2017   submitted
3       12 Jan 2017   submitted
4       18 Jan 2017   not submitted
5       06 Feb 2017   submitted
6       12 Feb 2017   not submitted
7       18 Feb 2017   submitted
8       25 Feb 2017   submitted
Percentage = 75%

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