Click here to Skip to main content
15,446,510 members
Please Sign up or sign in to vote.
1.67/5 (3 votes)
See more:
#include <iostream>
#include <string>
using namespace std;
struct subj {
	double f_mark;
	double lab_mark;
	double sec_mark;
	
};

struct student {
	string name;
	int rID;
	int age;
	subj s1;
	subj s2;
	subj s3;
	subj s4;
	subj s5;
};
double tot_marks(subj s) {

	double total = s.f_mark + s.lab_mark + s.sec_mark;
	return total;
}

double compute_average_mark(student s) {
	double avmark = ( tot_marks(s.s1) + tot_marks(s.s2) + tot_marks(s.s3) + tot_marks(s.s4) + tot_marks(s.s5)) / 5;
	return avmark;
}

double compute_total_mark(student s) {
	double totmark = (tot_marks(s.s1) + tot_marks(s.s2) + tot_marks(s.s3) + tot_marks(s.s4) + tot_marks(s.s5));
		return totmark;
}

string get_grade(student s) {
	if (compute_average_mark(s) > 100 || compute_average_mark(s) < 0)
		return ("out of range ... please check your input again") ;
	
	else {
		if (compute_average_mark(s) >= 90)
			return (" Exellent ");
		else if (compute_average_mark(s) < 90 && compute_average_mark(s) >= 80)
			return (" Well done ");
		else if (compute_average_mark(s) < 80 && compute_average_mark(s) >= 70)
			return (" Good  ");
		else if (compute_average_mark(s) < 70 && compute_average_mark(s) >= 60)
			return (" Need improvement ");
		else
			return (" fail ");
	}
}
void display_info(student s) {
	cout << " student name is " << s.name << endl;
	cout << " student id is " << s.rID << endl;
	cout << " student age is " << s.age << endl;
	cout << " student total mark is " << compute_total_mark(s) << endl;
	cout << " student grade is " << get_grade(s) << endl;
	cout << endl;
}
int main()
{
	int num;
	cout << "enter number of students \n";
	cin >> num;
	student* arr = new student[num];
	for (int i = 0; i < num; i++)
	{
		cout << "enter student's name & age & id \n";
		cin >> arr[i].name >> arr[i].age >> arr[i].rID;

		cout << "enter final & lab & section marks for subject 1 \n";
		cin >> arr[i].s1.f_mark >> arr[i].s1.lab_mark >> arr[i].s1.sec_mark;
		
		cout << "enter final & lab & section marks for subject 2 \n";
		cin >> arr[i].s2.f_mark >> arr[i].s2.lab_mark >> arr[i].s2.sec_mark;
		
		cout << "enter final & lab & section marks for subject 3 \n";
		cin >> arr[i].s3.f_mark >> arr[i].s3.lab_mark >> arr[i].s3.sec_mark;
		
		cout << "enter final & lab & section marks for subject 4 \n";
		cin >> arr[i].s4.f_mark >> arr[i].s4.lab_mark >> arr[i].s4.sec_mark;
		
		cout << "enter final & lab & section marks for subject 5 \n";
		cin >> arr[i].s5.f_mark >> arr[i].s5.lab_mark >> arr[i].s5.sec_mark;
		compute_average_mark(arr[i]);
		compute_total_mark(arr[i]);
	}

	for (int i = 0; i < num; i++)
	{
		display_info(arr[i]);
	}
	int temp=0;
	for (int i = 0; i < num; i++)
	{
		
		double temp1 = compute_average_mark(arr[0]);
		if (compute_average_mark(arr[i]) > temp1)
		{
			temp = i;
			temp1 = compute_average_mark(arr[i]);
		}
	}
	cout << "student with maximum grade is " << arr[temp].name << endl;
	cout << endl;

	int sID;
	cout << "enter a specific id \n";
	cin >> sID;
	for (int i = 0; i < num; i++)
	{
		if (sID == arr[i].rID)
			cout << "student with this id is " << arr[i].name << endl;
		else
			cout << "no student has this id \n";
	}
	system("pause");
	return 0;
}


What I have tried:

#include <iostream>
#include <string>
using namespace std;
struct subj {
	double f_mark;
	double lab_mark;
	double sec_mark;

};

struct student {
	char name;
	int rID;
	int age;
	subj s1;
	subj s2;
	subj s3;
	subj s4;
	subj s5;
};
double tot_marks(subj s) {

	double total = s.f_mark + s.lab_mark + s.sec_mark;
	return total;
}

double compute_average_mark(student s) {
	double avmark = (tot_marks(s.s1) + tot_marks(s.s2) + tot_marks(s.s3) + tot_marks(s.s4) + tot_marks(s.s5)) / 5;
	return avmark;
}

double compute_total_mark(student s) {
	double totmark = (tot_marks(s.s1) + tot_marks(s.s2) + tot_marks(s.s3) + tot_marks(s.s4) + tot_marks(s.s5));
	return totmark;
}

void get_grade(student s) {
	if (compute_average_mark(s) > 100 || compute_average_mark(s) < 0)
		printf("out of range ... please check your input again");

	else {
		if (compute_average_mark(s) >= 90)
			printf(" Exellent ");
		else if (compute_average_mark(s) < 90 && compute_average_mark(s) >= 80)
			printf(" Well done ");
		else if (compute_average_mark(s) < 80 && compute_average_mark(s) >= 70)
			printf(" Good  ");
		else if (compute_average_mark(s) < 70 && compute_average_mark(s) >= 60)
			printf(" Need improvement ");
		else
			printf(" fail ");
	}
}
void display_info(student s) {
	printf(" student name is\n ", s.name);
	printf( " student id is \n", s.rID);
	printf(" student age is\n ", s.age);
	printf (" student total mark is\n ", compute_total_mark(s));
	//printf (" student grade is \n",get_grade(s));
	printf("\n");
}
int main()
{
	int num;
	printf( "enter number of students \n");
	scanf_s("%d", num);
	student*arr = new student[num];
	for (int i = 0; i < num; i++)
	{
		printf( "enter student's name & age & id \n");
		scanf_s("%s%d%d", arr[i].name, arr[i].age, arr[i].rID);

		printf("enter final & lab & section marks for subject 1 \n");
		scanf_s("%d%d%d", arr[i].s1.f_mark, arr[i].s1.lab_mark, arr[i].s1.sec_mark);


		printf("enter final & lab & section marks for subject 2 \n");
		scanf_s("%d%d%d", arr[i].s2.f_mark, arr[i].s2.lab_mark, arr[i].s2.sec_mark);

		printf("enter final & lab & section marks for subject 3 \n");
		scanf_s("%d%d%d", arr[i].s3.f_mark, arr[i].s3.lab_mark, arr[i].s3.sec_mark);

		printf("enter final & lab & section marks for subject 4 \n");
		scanf_s("%d%d%d", arr[i].s4.f_mark, arr[i].s4.lab_mark, arr[i].s4.sec_mark);

		printf("enter final & lab & section marks for subject 5 \n");
		scanf_s("%d%d%d", arr[i].s5.f_mark, arr[i].s5.lab_mark, arr[i].s5.sec_mark);

		compute_average_mark(arr[i]);
		compute_total_mark(arr[i]);
	}

	for (int i = 0; i < num; i++)
	{
		display_info(arr[i]);
	}
	int temp = 0;
	for (int i = 0; i < num; i++)
	{

		double temp1 = compute_average_mark(arr[0]);
		if (compute_average_mark(arr[i]) > temp1)
		{
			temp = i;
			temp1 = compute_average_mark(arr[i]);
		}
	}
	printf("student with maximum grade is ", arr[temp].name);
	printf("\n");

	int sID;
	printf("enter a specific id \n");
	scanf_s("%d", sID);
	for (int i = 0; i < num; i++)
	{
		if (sID == arr[i].rID)
			printf("student with this id is ", arr[i].name); 
		else
			printf( "no student has this id \n");
	}
	//system("pause");
	return 0;
}
Posted
Updated 9-Jun-21 4:55am
Comments
Richard Deeming 9-Jun-21 10:41am     CRLF
Well, go ahead - you have our permission. This is not a code conversion service. If you want to convert the code, you'll need to do it yourself.
Patrice T 9-Jun-21 10:51am    
And you have a problem ?

1 solution

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

You need to replace the above three lines with:
C++
#include <stdlib.h>
#include <stdio.h>
 
Share this answer
 
Comments
CPallini 9-Jun-21 11:08am    
5.
Richard MacCutchan 9-Jun-21 11:30am    
:thumbsup:
Greg Utas 9-Jun-21 11:08am    
5. How unusual for someone to actually post a decent conversion. But it's strange that he didn't know to change the #includes.
Richard MacCutchan 9-Jun-21 11:30am    
Thanks. Yes, I wondered about that.

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