Question
Hi guys, I am stuck at some parts I was just wondering if someone can take a look at my code and provide a sample
Hi guys, I am stuck at some parts I was just wondering if someone can take a look at my code and provide a sample code so that I can compare. Thank you.
Here is the requirement:
*note:be aware of the Weighted Average Requirement in the course (students must achieve a combined weight of at least 50% across all invigilated components). Students missing 30% or more submissions will receive a UN Students missing more than 30% of classes will receive a UN
-User can print print a report of the students grade at any time. The user have no restriction on the number of assignments they can enter. Printing the report will show all the assessments for the course, the user will also see a FINAL REPORT of the course achievement (See Appendix). User can enter the commands: a Enter an assessment r Print the Report q Quit the program If the student is absent for assessments that amount to more than 30% of the weighted total of the exams they receive a UN regardless of their weighted average. If the student achieves more than 50% weighted average then they pass. If the student achieves less than 50% weighted average then they fail.
My code is:
//Keep the total number of points
//Keep the total score
//Keep the total number of missed points
//Keep a variable for the report output
//Go into a loop until the user exits
$check = true;
$totalScore = 0;
$output =0;
$totalPoints = 0;
while ($check == true)
{
//Prompt the user
$command ="";
//Read in the command
echo "Please enter your command in the form of (a, r, q) ";
$command = stream_get_line(STDIN, 1024, PHP_EOL);
switch($command)
{
//If the command is ....
case 'q':
echo "Bye";
$check = false;
break;
//Prompt the user for assessment details
case 'a':
$output++;
echo " PHP Lab 1 - TAVu - 85032 ";
//Enter the name of the assessment
echo "Enter the name of the assessment ";
${"nameOfAssessment".$output} = stream_get_line(STDIN, 1024, PHP_EOL);
//Enter the number of points for the assessment
echo "Enter the number of points for the assessment";
${"assessmentPoints".$output}= stream_get_line(STDIN, 1024, PHP_EOL);
//Check if the user was absent, keep asking until the user enters a y or a n.
//Another while loop
echo "Was the student absent? (y): ";
${"absent".$output}= stream_get_line(STDIN, 1024, PHP_EOL);
while ($sentinel == true)
{//Was the user absent?
//If the user entered a y or a n then exit
//If the student was absent
if (${"absent".$output} == "y")
{
//Write a message to the console
echo "The student has been maked absent for this assignment.";
//add the missed points to the total
$totalScore = "0";
//SEt the score to zero
}
else
{
echo "Please enter the student's score for the assessment: ";
${"assessmentScore".$output} = stream_get_line(STDIN,1024,PHP_EOL);
}
}
//Update the totals (Points and Score)
$totalPoints += ${"assessmentPoints".$output};
$totalScore += ${"assessmentScore".$output};
//Start the Report we have all the data we need
//print seperator
break;
case 'r':
//If print the report.
printf ("----------------------------------------");
$report .= sprintf("%'-80s ",'');
for ($i=1; $i
{
//Append the assignment name
printf("%10s Assignment: %30s ", "", ${"nameOfAssessment".$i});
//Append the Total Points
printf("%10s Total Points: %30s ", "", ${"assessmentPoints".$i});
//Append the Total Score
printf("%10s Total Score: %30s ", "", ${"assessmentScore".$i});
//Append the Missed
printf("%10s Missed: %30s ", "", ${"absent".$i});
//Append seperator
printf ("----------------------------------------");
echo " ";
$totalPoints += ${"assessmentPoints".$i};
$totalScore += ${"assessmentScore".$i};
}
//Compile the final Report
//Calculated the weighted average
//Calculate the missed percentage
//Whas it a UN?
//if not
//PASS
//FAIL
//Print seperator
$finalReport = sprintf("%'-80s ",'');
$finalReport .= sprintf("%40s","FINAL REPORT")." ";
//Print the weighted average
//Print the missed percentage
//Print outcome final outcome
//Print seperator
printf ("----------------------------------------");
$finalReport .= sprintf("%'-80s ",'');
echo $report;
echo $finalReport;
break;
//Hit the default? Cant recognize the command?
default:
echo "Please enter a valid command ";
break;
}
}
?>
This is the output sample:
Appendix Enter Assessments: hp Lab@1_SWA_56789.php oder SE Please enter your command in the form of (a, r, q)a Please enter the name of the assessment: Quizi Please enter the number of points for the assessment: 10 Was the student absent? (y)n. Please enter the student's score for the assessment: 6 Please enter your command in the form of (a, r, qa Please enter the name of the assessment: Quiz2 Please enter the number of points for the assessment: 10 Was the student absent? (ynnn Please enter the student's score for the assessment: 4 Print Report: 10 ease er Total Score: Please enter your command in the form of (a, r or - nd in the form ora ---- lease en cen tinand in the form ota , P Qua .. ease Total Points: of the assessment: Quizi ber of points for the assessment: 18 S the studer Missed: 9 Lease enter the lents...score for the assessment.------- ease enter your command-in-theforn_on_a_--02---- lease en Assiroment of the assessment: Quiz2 Wer of points for the assessment: 10 CIN ease Total Points: s the Total Score: lease enter Missed: dient's score for the assessment: a 156A p orted to save as displaying dialog - - --- --- --- -- --- - -- --- -- FINAL REPORT Weighted Average: 0.50% Missed PercentagesthersNOT FOR REDISTRUBUTTON 0.00% ENTS FOUND REDES Otcom QURSE MATERIAL WILL BE INVIOLATION OF ACADEMIC IN Doce POLICIES AND WTED FACT New Outcome: PLINARY ACTION BY DMINISTRATION. - - --- ---- --- --= = === === == == --- - -- -- --- --- --- -- - Please enter your command in the form of (a, r, ogStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started