Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a problem-based task question which is the question is Your team have to develop a simple program that will be use by Department of Examination at STAR College. The program can accept information of TEN (10) students such as name, registration number and results for THREE (3) courses. Thecourses taken by the students are Database Design (DB), Introduction to Python (IP) and Network Design (ND). The program can determine grade for each course based on the Figure 1 below.
Please help me. Thank you.

What I have tried:

C++
#include <iostream>
using namespace std;

struct student;
{
    string name[50];
    int regNumber;
    int dbMarks, ipMarks, ndMarks;
}s[10];

int main()
{
    cout << "Enter information of 10 students: " << endl;

    // storing information
    for(int i = 0; i < 10; ++i)
    {
        cout << "Enter name: ";
        cin >> s[i].name;

        cout << "Enter Database Design marks: ";
        cin >> s[i].dbMarks;

        cout << "Enter Introduction to Python marks: ";
        cin >> s[i].ipMarks;

        cout << "Enter Network Design marks: ";
        cin >> s[i].ndMarks;

        cout << endl;
    }

    if(75 <= mark <= 100)
        cout << "A";
    else if(65 <= mark <= 74)
        cout << "B";
    else if(55 <= mark <= 64)
        cout << "C";
    else if(40 <= mark <= 54)
        cout << "D";
    else if(0 <= mark <= 39)
        cout << "E";
    else
        cout << "error message";
    cout << endl;


    cout << "Displaying Information: " << endl;

    // Displaying information
    for(int i = 0; i < 10; ++i)
    {
        cout << "Name: " << s[i].name << endl;
        cout << "Grade of Database Design: " << s[i].db_marks << endl;
        cout << "Grade of Introduction to Python: " << s[i].ip_marks << endl;
        cout << "Grade of Network Design: " << s[i].nd_marks << endl;
    }

    return 0;
}
Posted
Updated 28-Nov-22 1:43am
v3
Comments
Richard MacCutchan 28-Nov-22 6:26am    
You need to explain what the problem is.

You should put the code assigning the grades in a separate function. Try
C++
#include <iostream>
using namespace std;

enum
{
  eDB,
  eIP,
  eND,
  COURSES,
  STUDENTS = 10,
};

struct Student
{
    string name;
    int regNumber;
    int marks[COURSES];
};

const string grade(int marks );

int main()
{
    Student s[STUDENTS];
    const string CourseTitle[COURSES] = { "Database Design", "Introduction To Python", "Network Design" };

    cout << "Enter information of 10 students: " << endl;

    // storing information
    for(int i = 0; i < STUDENTS; ++i)
    {
        cout << "Enter name: ";
        cin >> s[i].name;
        cout << "Enter registration number: ";
        cin >> s[i].regNumber;

        for ( unsigned n = 0; n < COURSES; ++n)
        {
          cout << "Enter " << CourseTitle[n] << " marks: ";
          cin >> s[i].marks[n];
        }
    }

    cout << "Displaying Information: " << endl;

    // Displaying information
    for(int i = 0; i < STUDENTS; ++i)
    {
        cout << "Name: " << s[i].name << endl;
        cout << "Registration Number" << s[i].regNumber << endl;
        for (unsigned n = 0; n < COURSES; ++n)
        {
          cout << "Grade of " << CourseTitle[n] <<  " " << grade( s[i].marks[n] ) << endl;
        }
    }
    return 0;
}

const string grade(int marks )
{
    if ( marks > 100 || marks < 0)
      return "ERROR";
    else if ( marks > 74)
      return "A";
    else if ( marks > 64)
      return "B";
    else if ( marks > 54)
      return "C";
    else if ( marks> 39 )
      return "D";
    else
      return "E";
}
 
Share this answer
 
Take away the semicolon after the word "student":
C++
struct student;
              ^
              |
{
    string name[50];
    int regNumber;
    int dbMarks, ipMarks, ndMarks;
}s[10];

You should expect to get syntax errors every day, probably many times a day while you are coding - we all do regardless of how much experience we have! Sometimes, we misspell a variable, or a keyword; sometimes we forget to close a string or a code block. Sometimes the cat walks over your keyboard and types something really weird. Sometimes we just forget how many parameters a method call needs.

We all make mistakes.

And because we all do it, we all have to fix syntax errors - and it's a lot quicker to learn how and fix them yourself than to wait for someone else to fix them for you! So invest a little time in learning how to read error messages, and how to interpret your code as written in the light of what the compiler is telling you is wrong - it really is trying to be helpful!

So read this: How to Write Code to Solve a Problem, A Beginner's Guide Part 2: Syntax Errors[^] - it should help you next time you get a compilation error!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900