GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #21  
Old 18-Oct-2009, 02:16
chekers chekers is offline
New Member
 
Join Date: Oct 2009
Posts: 15
chekers is on a distinguished road

Re: Convert to structure


CPP / C++ / C Code:
#include <stdio.h>

struct Course
{
  int CreditHours; // 2, 3, or 4
  int Mark; // 0 to 100
};

struct Student
{
  char Name[32]; // Up to 31 characters long
  struct Course Courses[3]; // An array of 3 courses
};

{
 void PrintName( Student * student)
 student(); 
}

 int AddMarks(Student *student)

 int main(void)
{
  int i;
  for(i= 0; i < 3; ++i) sum += student->Courses[i].Mark;
  return sum;
}
int main()
{
  printf("Hello World");
  getchar();
  return 0;
}

Code:
Compiling... g.c C:\Users\Viper\Desktop\g.c(15) : error C2449: found '{' at file scope (missing function header?) C:\Users\Viper\Desktop\g.c(18) : error C2059: syntax error : '}' Error executing cl.exe. g.exe - 2 error(s), 0 warning(s)

plz help me...i need to submit this in 2 days time.....HELP...HELP...im really a noob with c...
  #22  
Old 18-Oct-2009, 11:08
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 802
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: Convert to structure


Holy crap. That's the best you can do? You've got two main()'s in there!

Do yourself a favor and give the weed to a good friend (who doesn't smoke
weed) for a few days so you can pay attention and get this assignment done!

You titled this thread "Convert to Structure" but it doesn look to me like
you are ready for C structures or even functions. .
Your assignment mentions neither and barely mentions "array".
It looks like it's intended to point out that arrays can only hold one data
and how difficult it becomes to manage data of different types with them .
Seems to me that your level is just a notch up from "hello world"... so
you should just be keeping your whole program in the main() function
and not worry about adding other functions at this point..

So go back to that assignment you posted and break it out into
the main tasks and sub tasks that will need to be done:
Code:
Write a program that will read - the name of a student - and the three marks from three different courses entered by a user. - For each course the credit hour is specified as 2, 3 or 4. The program continues to take these inputs until the maximum number of students (the maximum number is determined by the user). Store these inputs in the array. Calculate the GPA for each student based on the Grade Point below: Marks Range Grade Grade point: 80 - 100 A 4 70 - 79 B 3 60 - 69 C 2 50 - 59 D 1 0 - 49 F 0 Example: Course A 87 A 3 credit hour Course B 77 B 3 credit hour Course C 65 C 3 credit hour So, GPA = ((3 X 4) + (3 X 3) + (3 X 2)) / 9 = 3.00
So you get an idea of what needs to be done.
You alse referred us to an image which showed an samle run sequence:
Code:
Enter number of student 3 Enter a name james Enter mark for course 1, 2 and 3 45 56 78 Enter credit hour for dourse 1, 2 and 3 3 3 3 Enter a name samuel Enter mark for course 1, 2 and 3 56 87 88 Enter credit hour for course 1, 2 and 3 3 3 3 Enter a name kevin Enter mark for course 1, 2 and 3 78 89 90 Enter credit hour for course 1, 2 and 3 3 3 3 You have entered james whose GPA is 1.33 You have entered samuel whose GPA is 3.00 You have entered kevin whose GPA is 3.67 Thank you Press any key to continue.
That gives an even better idea of what to do.

So start from step one and write your own work instead of guessing your way
through others'. Suppose you just get the user input portion done first and
then move on to the calculation part. For example:
CPP / C++ / C Code:
#include <stdio.h>

int main(void)
{
  char    names[16][16] = {{0}};  /* to store 16 names of 16 chars max each */
  double grades[16][5]  = {{0}};  /* to store 16  sets 5 doubles each       */
  int   credhrs[16][5]  = {{0}};  /* to store 16  sets 5 ints each          */
  int i;
  int num_students = 0;

  printf("Enter number of student \n");
  scanf("%d", &num_students);     /* hate using scanf() but at your level... */

  for( i = 0; i < num_students; i++ ) /* get the data for each student */
  {
    printf("Enter a name \n");
    scanf("%s", names[i]);
    getchar();
    printf("Enter mark for course 1, 2 and 3 \n");
    scanf("%lf%lf%lf", &grades[i][0], &grades[i][1] , &grades[i][2] );/*how cheap*/
    getchar();
    printf("Enter credit hour for course 1, 2 and 3 \n");
    scanf("%d%d%d", &credhrs[i][0], &credhrs[i][1] , &credhrs[i][2] );
    getchar();
  }
  printf("Printing Report: \n\
Name          grades      respective credhrs \n\
------------------------------------------------------------------------\n");
  for( i = 0; i < num_students; i++ ) /* print the data for each */
  {
    printf("%10s    ", names[i] );
    printf("%.3f  %.3f  %.3f    ", grades[i][0], grades[i][1] , grades[i][2] );
    printf("  %d  %d  %d \n", credhrs[i][0], credhrs[i][1] , credhrs[i][2] );
  }

  return 0;
}
Sample run:
Code:
Enter number of student 3 Enter a name Chuck Enter mark for course 1, 2 and 3 83 84 93 Enter credit hour for course 1, 2 and 3 2 3 4 Enter a name Bo Enter mark for course 1, 2 and 3 85 97 82 Enter credit hour for course 1, 2 and 3 3 4 2 Enter a name Buck Enter mark for course 1, 2 and 3 68 82 97 Enter credit hour for course 1, 2 and 3 3 3 3 Printing Report: Name grades respective credhrs ------------------------------------------------------------------------ Chuck 83.000 84.000 93.000 2 3 4 Bo 85.000 97.000 82.000 3 4 2 Buck 68.000 82.000 97.000 3 3 3
That should get you going.
Make a plan of the changes you will need to make and impement them
ONE AT A TIME!!!! and test test test...
  #23  
Old 21-Oct-2009, 09:24
chekers chekers is offline
New Member
 
Join Date: Oct 2009
Posts: 15
chekers is on a distinguished road

Re: Convert to structure


CPP / C++ / C Code:
#include <stdio.h>


struct student_struct
{

char student_name[31];
int mark_cs1;
int mark_cs2;
int mark_cs3;
int ch_cs1;
int ch_cs2;
int ch_cs3;
int gpa;
};


void input_student_data(struct student_struct *st_rec);

int computed_gpa(int average);


int main(void)
{
	struct student_struct student_record;
	
		{
		input_student_data(&student_record);


		printf("student name   :%s\n",student_record.student_name);
		printf("with gpa  :%c\n",(student_record.gpa));

		

	}
	return 0;

}

void input_student_data(struct student_struct *s)
{

	
	printf("enter student name   :");
	gets(s->student_name);
	printf("enter mark for course 1  :");
	scanf("%d",  &s->mark_cs1);
	printf("enter mark for course 2 :");
	scanf("%d",  &s->mark_cs2);
	printf("enter mark for course 3 :");
	scanf("%d",  &s->mark_cs3);
	printf("enter credit hour for course 1 :");
	scanf("%d",  &s->ch_cs1);
	printf("enter credit hour for course 2  :");
	scanf("%d",  &s->ch_cs2);
	printf("enter credit hour for course 3  :");
	scanf("%d",  &s->ch_cs3);
}


  	int computed_gpa(int gpa)
		{
			char grade;

			if(gpa >=90)
				grade = '4';
			else if(gpa >=80)
				grade = '3';
			else if(gpa >=70)
				grade = '2';
			else if(gpa >=60)
				grade = '1';
			else
				grade = '0';
			return grade;
		}


plz help me with the calculation part...

like i enter :
mark course 1= 45
mark course 2=67
mark course 3= 88
cdt hour for course 1= 3
cdt hour for course 2= 2
cdt hour for course 3= 4


so the calculation will go like this :
mark course 1* cdt hour course1 +mark course 2* cdt hour course2+mark course 3* cdt hour course3 / total cdt hour of course 1,2,3 ..

and it follow this rule
CPP / C++ / C Code:
char grade;

			if(gpa >=90)
				grade = '4';
			else if(gpa >=80)
				grade = '3';
			else if(gpa >=70)
				grade = '2';
			else if(gpa >=60)
				grade = '1';
			else
				grade = '0';
			return grade;
		}


where in output....it will show the gpa.... plz help me....i've done something rather then nothin....i need to submit it tomorrow...please...Thanks alot again...
  #24  
Old 21-Oct-2009, 10:34
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 713
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: Convert to structure


You really need to think about your data types. It seems to me that a GPA should hold real numbers (float or double), not just whole numbers (int).

In other words, compute_gpa() should take a student_struct* as a parameter and fill that structure's gpa (float) field. Maybe something like:
CPP / C++ / C Code:
void compute_gpa(struct student_struct *s)
{
  s->gpa = .....
}
 
 

Recent GIDBlogToyota - 2009 May Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Structure with in a structure knockout_artist C Programming Language 3 19-Dec-2007 12:08
Allocating memory to a structure Printisor C Programming Language 4 29-Jun-2007 09:00
Convert the input into square yards pjpav Java Forum 1 08-Oct-2005 08:43
[CONTEST?]Data Structure Test dsmith C Programming Language 2 06-Jun-2004 16:13

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:06.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.