0% found this document useful (0 votes)
30 views

Secp 1013 Programming Technique

Uploaded by

Rayen
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Secp 1013 Programming Technique

Uploaded by

Rayen
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

SECP 1013 PROGRAMMING TECHNIQUE

GROUP PROJECT (REPORT)

SECTION : 02

SEMESTER : 20232024/2

PREPARED FOR : DR CIK SUHAIMI BIN YUSOF

PREPARED BY : GROUP 5

NAME MATRIC NO.

KIRTIGEN A/L VIJAYAKUMAR A23KT0100

MUHAMMAD ALIF HAIQAL WAN MOHD AZMAN A23KT0135

RAYEN RAYMOND A23KT0210


CONTENT

1. Introduction 3
2. Task Distribution In A Team 4
3. Design Flowchart 5
4. Code/Program 6-11
4.1. Input
4.2. Output
5. Input Data File 12-13
6. Output On Screen & Output File 14-15
7. Video Project Link 16
8. Closing/Summary 16-18
1.0 INTRODUCTION

Assalamualaikum w.b.t. and warm greetings to our esteemed lecturer, Dr. Cik Suhaimi Bin
Yusof.We would like to express our deepest gratitude for your unwavering support and guidance
throughout our SECP 1013 Programming Technique course. Your dedication and expertise have
been invaluable in helping us complete this project.We also extend our sincere appreciation to our
Group 5 members: Kirtigen a/l Vijayakumar, Alif Haikal, and Rayen Reymond, for their
cooperation, innovative ideas, and tireless efforts. Working together as a team has been an
incredible experience, and we are thrilled to have shared this journey.Our project aimed to apply
the programming techniques we've learned in this course to solve a real-world problem. We began
by carefully understanding the problem statements, then designed solutions using flowcharts and
C programming. We translated our logical designs into executable C programs, utilizing various
programming constructs such as arithmetic expressions and arrays.Throughout this project, we
encountered several challenges that tested our problem-solving skills. However, these challenges
helped us develop a deeper understanding of the subject matter. We gained substantial practical
experience, particularly in debugging and optimizing code.

We hope that the solutions and coding presented in this project will serve as a valuable resource
for others studying this course. Our experiences and the knowledge we've gained can provide
guidance and inspiration for fellow students embarking on similar projects.In conclusion, we are
grateful for the opportunity to apply our learning in a practical context. We look forward to
continuing our journey in the field of programming with renewed confidence and enthusiasm.
2.0 TASK DISTRIBUTION IN A TEAM

No. Task Member Assigned


1. Cover Page & Content Table Kirtigen

2. Introduction Kirtigen

3. Report Outline Kirtigen

4. Task Distribution Kirtigen

5. Design-Flowchart Alif Haikal

6. Code/Program Rayen

7. Input Data File Rayen

8. Output On Screen Rayen

9. Output File Alif Haikal

10. Video Project Link Kirtigen

11. Closing/Summary Alif Haikal


3.0 DESIGN(FLOWCHART)
4.0 CODE/PROGRAM

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#define MAX_STUDENTS 20

#define MAX_QUESTIONS 20

// Structure to store student information

typedef struct {

char id[10];

char name[20];

char answers[MAX_QUESTIONS + 1];

int missed;

float percentage;

char grade;

} Student;

// Function prototypes

void readFile(Student students[], int *numStudents);

void readCorrectAnswers(char correctAnswers[]);

void compareAnswers(Student students[], int numStudents, char correctAnswers[]);

void printMissedQuestions(Student student, char correctAnswers[]);

void printReport(Student students[], int numStudents, char correctAnswers[]);


int main() {

Student students[MAX_STUDENTS];

int numStudents = 0;

char correctAnswers[MAX_QUESTIONS + 1];

// Read student answers and correct answers from files

readFile(students, &numStudents);

readCorrectAnswers(correctAnswers);

// Compare student answers with correct answers

compareAnswers(students, numStudents, correctAnswers);

// Print report to output file

printReport(students, numStudents, correctAnswers);

return 0;

// Function to read student answers from file

void readFile(Student students[], int *numStudents) {

FILE *fp = fopen("StudentAnswers.dat", "r");

if (fp == NULL) {

printf("Failed to open StudentAnswers.dat\n");

exit(1);

}
while (fscanf(fp, "%s %s", students[*numStudents].name, students[*numStudents].id) != EOF) {

for (int i = 0; i < MAX_QUESTIONS; i++) {

fscanf(fp, " %c", &students[*numStudents].answers[i]);

students[*numStudents].answers[MAX_QUESTIONS] = '\0';

students[*numStudents].missed = 0;

students[*numStudents].percentage = 0.0;

students[*numStudents].grade = ' ';

(*numStudents)++;

fclose(fp);

// Function to read correct answers from file

void readCorrectAnswers(char correctAnswers[]) {

FILE *fp = fopen("CorrectAnswers.txt", "r");

if (fp == NULL) {

printf("Failed to open CorrectAnswers.txt\n");

exit(1);

fscanf(fp, "%s", correctAnswers);

fclose(fp);

}
// Function to compare student answers with correct answers

void compareAnswers(Student students[], int numStudents, char correctAnswers[]) {

for (int i = 0; i < numStudents; i++) {

for (int j = 0; j < MAX_QUESTIONS; j++) {

if (students[i].answers[j] != correctAnswers[j]) {

students[i].missed++;

students[i].percentage = ((float)(MAX_QUESTIONS - students[i].missed) /


MAX_QUESTIONS) * 100;

if (students[i].percentage >= 80) {

students[i].grade = 'A';

} else if (students[i].percentage >= 70) {

students[i].grade = 'B';

} else if (students[i].percentage >= 60) {

students[i].grade = 'C';

} else {

students[i].grade = 'F';

// Function to print missed questions for a student

void printMissedQuestions(Student student, char correctAnswers[]) {

printf("EXAM RESULT\n");

printf("Name: %s\n", student.name);


printf("Student ID: %s\n", student.id);

printf("Number of questions missed: %d\n", student.missed);

printf("List of the questions missed:\n");

printf("Question\tCorrect Answer\tStudent Answer\n");

for (int i = 0; i < MAX_QUESTIONS; i++) {

if (student.answers[i] != correctAnswers[i]) {

printf("%d\t\t%c\t\t%c\n", i + 1, correctAnswers[i], student.answers[i]);

printf("Percentage: %.2f%%, GRADE: %c\n", student.percentage, student.grade);

// Function to print report to output file

void printReport(Student students[], int numStudents, char correctAnswers[]) {

char id[10];

printf("Enter the student ID: ");

scanf("%s", id);

FILE *fp = fopen("output.txt", "w");

if (fp == NULL) {

printf("Failed to create output.txt\n");

exit(1);

fprintf(fp, "Name\tID\tPercentage\tGrade\n");

for (int i = 0; i < numStudents; i++) {


fprintf(fp, "%s\t%s\t%.2f%%\t%c\n", students[i].name, students[i].id, students[i].percentage,
students[i].grade);

if (strcmp(students[i].id, id) == 0) {

printMissedQuestions(students[i], correctAnswers);

fclose(fp);

printf("Report has been written to output.txt successfully.\n");

}
5.0 INPUT DATA FILE

StudentsAnswer.dat

Abdullah A19EE0180 A B C F B A B A A C A C B A B C A C A A

LuDong A19EE0160 A B D D A C B D D B C A A D C D A B C D

Syarifah AC12CS678 A A D C B C D D A B C C A A C D A D C D

Sivarajah AC12CS123 C B C B A C C D B B C C A B C D C C C D

Wendy B19EE0167 A C C D A B C C A A C D A A A D A B C D

Raj A19EE0170 B C A C B B B A C B A C B C A B A C B A

Liew A19EE1234 C B C C B A B C A A B B A B C B B C A A

Chong B19EE1234 C A B B C A C C B A B B B A A A C A A A

Azad B19EE4321 C B C A A A B A C B A A B C A C B A A A

Tan AC12CS312 C B C A A A C B C A B B A C B C B A C A

Isaac AC12CS324 C A A B A A B C B A C A B C B A B C A A

Chau A19EE4321 A B C B B A B A A C A C B A B C A C A A

Kumar A19EE1234 A B C D A B C D A B C D A B C D A B C D

Alip A19EE2143 C B A A C A A C B B B A A A A A A A A A

Lee AC12CS223 C B C B B A B A A C A C B A B C A C C C

Ismail B19EE2211 B A C A B A C A B C A A A C C B A A B A

John B19EE1212 A A C C A B B C A A C B B C A B A A C A

Aszue AC12CS456 B B A B A C A A C A B B C B C A C A A A

Jason AC12CS678 A B C A B A A A A C A C A A B C A C A A

Joven A19EE2707 B D A D D C B A A B C A B A C A C B A A
CorrectAnswers.txt

ABCDABCDABCDABCDABCD
6.0 OUTPUT (ON SCREEN & OUTPUT FILE)

Output on screen
Output file
7.0 VIDEO PROJECT LINK

https://drive.google.com/file/d/1cB0ixi72jqkpgNo4UayOdM2Jjd3iyExU/view?usp
=drivesdk
8.0 SUMMARY

From this project, we have learned the application and the techniques in the C Programming the
knowledge that we had in the class. Starting from understanding the question, flowchart, arranging
what might be in the coding, a lot of challenges and learning and also developed our problem solving
skills and new things on how to implement the file into the code. Through this project, we learned
the importance of teamwork and collaboration, as well as the value of clear communication and
documentation. We are confident that these skills will serve us well in our future programming
endeavors.We have some function prototypes that we wanted to highlight from this project which are ;

readFile = Reads input data from the inserted files.


readCorrectAnswers= Read the correct answer that applied in CorrectAnswers.txt file.
compareAnswers = Compares student's answers with correct answers.
printMissedQuestions = Displays missed questions and correct answers.
printReport = Displays the output on the screen and writes it to the output file.

This project has been an enriching and educational experience that has allowed us to deepen our
understanding of C programming and its practical applications. We have learned how to define and
implement multiple functions, each with a specific purpose, and how to use function parameters to
pass data between functions. This approach has helped us avoid the use of global variables and
ensured that all data is passed explicitly.Throughout the project, we gained valuable experience in
reading input data from text files and storing this data in arrays for further processing. We also learned
how to compare students' answers with the correct answers, determine the number of questions
missed, and calculate the percentage of correctly answered questions. This information was then used
to determine a grade for each student.In addition, we learned how to format and display results on the
screen, including detailed information about missed questions and overall performance. We also
gained experience in writing output data to a text file, creating a comprehensive report of all students'
performances.

Overall, this project has significantly enhanced our understanding of C programming, especially in
areas such as file I/O, array manipulation, function implementation with parameter passing, and
generating formatted output. We have gained practical experience in designing, implementing, and
testing a complete C program, which will be invaluable in our future programming endeavors.

As we move forward, we are excited to continue building upon the skills and knowledge we have
gained through this project. We are confident that our renewed understanding of C programming will
serve us well in our future academic and professional pursuits. We look forward to continuing to learn
and grow as programmers, and to applying our skills to solve real-world problems.

You might also like