GIDForums  

Go Back   GIDForums > Computer Programming Forums > MS Visual C++ / MFC Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 12-Apr-2006, 09:52
Disfunctional04 Disfunctional04 is offline
New Member
 
Join Date: Mar 2006
Posts: 3
Disfunctional04 is on a distinguished road

Beginner


Hey, i have been in a programming class for a semester but i still haven't got it all figured out. I would like to ask someone to help me write a program that read's students names followed by the test scores. The program should output each student's name followed by the setst scores and the relevant grade. It should als find and print the highest test score and the name of the students having the highest test score.

Student dats should be stored in a struct variable for the type StudentType, which has four components: studentFName and studentLName of the type string, testScore of the type int (testScore is between 0 and 100), and grade of the type char. Suppose that the class has 20 students. Use an array of 20 components of the type studentType.

If someone could help me out it would be appreciated, thanks.
  #2  
Old 12-Apr-2006, 11:21
Paramesh's Avatar
Paramesh Paramesh is offline
Regular Member
 
Join Date: Sep 2005
Location: The Milky Way
Posts: 927
Paramesh is a jewel in the roughParamesh is a jewel in the roughParamesh is a jewel in the rough

Re: Beginner


What is your progress so far?

If you have any doubts/questions regarding the program, dont hesitate to ask.
But please dont ask us to do the entire program..


Regards,
Paramesh.
__________________

Don't walk in front of me, I may not follow.
Don't walk behind me, I may not lead.
Just walk beside me and be my friend.
  #3  
Old 12-Apr-2006, 23:53
Disfunctional04 Disfunctional04 is offline
New Member
 
Join Date: Mar 2006
Posts: 3
Disfunctional04 is on a distinguished road

Re: Beginner


Haha, i will show you what i have so far when i get back to my class, i meant to post it earlier but i ran out of time
  #4  
Old 17-Apr-2006, 09:02
Disfunctional04 Disfunctional04 is offline
New Member
 
Join Date: Mar 2006
Posts: 3
Disfunctional04 is on a distinguished road

Re: Beginner


CPP / C++ / C Code:
#include <string>
#include <fstream>
#include <iostream>
using namespace std;

int main()
{


	ifstream infile;
	ofstream outfile;  //output file stream variable

	infile.open("GradeResults.txt");

	if (!infile)
	   {
		   cout <<"Cannot open input file." <<endl;
		   return 1;
	   }

	cin >> student.Firstname >> student.LastName;
	cin >> student.testscore
	

	if (score >= 90)
		newStudent.courseGrade = 'A';
	else if (score >= 80)
			newStudent.courseGrade = 'B';
	else if (score >= 70)
			newStudent.courseGrade = 'C';
	else if (score >= 60)
			newStudent.courseGrade = 'D';
	else
		newStudent.courseGrade = 'F';

	void bubbleSort ( int list [], int length);

	int main ()
	{
		int list[] = {
Last edited by cable_guy_67 : 19-Apr-2006 at 09:40. Reason: Please enclose c++ code in [c++] ... [/c++] tags
  #5  
Old 19-Apr-2006, 09:14
locomonkey locomonkey is offline
New Member
 
Join Date: Mar 2006
Posts: 2
locomonkey is on a distinguished road

Re: Beginner


CPP / C++ / C Code:
//This program reads in  twenty student's names and grades, calculates a letter grade  and returns the 
//student with the highest score.

//Header Files
#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>

using namespace std;

// Declares Struct variable
struct studentType
{
	string studentFName;//Stores the student's first name
	string studentLName;//Stores the student's last name
	int testscore;//stores the test score
	char grade;//stores letter grade
};

studentType students[19];//initializes an array called students of the type studentType

//Declare functions

void GetData(ifstream& infile, studentType students[]);
void AssignGrade(ifstream& infile, studentType students[]);
int Highestscore(ifstream& infile, studentType students[]);
void PrintNames(ofstream&outfile, studentType students[]);
void bubblesort(ifstream& infile, studentType students[]);

int main(int argc, char* argv[])
{

	cout<< "This program reads in students' names followed by their test scores.  It will print"<<
		" the names and the highest test scores." << endl;
	ifstream infile;
	ofstream outfile;

	infile.open("Ch11_Ex1Data.txt");

	if (!infile)
	{
		cout << "Cannot open the input file." << endl;
		return 1;
	}
	outfile.open("Ch11_Ex1Results.txt");

	GetData(infile, students);
	AssignGrade(infile, students);
	Highestscore(infile, students);
	PrintNames(outfile, students);
	
	infile.close();
	outfile.close();

	return 0;
}


//Functions
void GetData(ifstream& infile, studentType students[])//This function reads in the data
{ 
	int index;
	for (index = 0; index <= 19; index++)
	{
		infile >> students[index].studentFName;
		infile >> students[index].studentLName;
		infile >> students[index].testscore;
	}
}

void AssignGrade(ifstream& infile, studentType students[])//This function assigns a letter grade to the grade
{
	int score;
	int index;
	for (index = 0; index <= 19; index++)
	{
	
	infile >> students[index].testscore;
	score = students[index].testscore;
	if (score >= 90)
		students[index].grade = 'A';
	else if (score >= 80)
		students[index].grade = 'B';
	else if (score >= 70)
		students[index].grade = 'C';
	else if (score >= 60)
		students[index].grade = 'D';
	else
		students[index].grade = 'F';
	}


}

int Highestscore(ifstream& infile, studentType students[])// This function outputs the highest grade
{
	int index;
	for (index = 0; index <= 19; index++)
	{
	infile >> students[index].testscore;
	bubblesort(infile, students);
	return students[index].testscore;
	}
}

void bubblesort(ifstream& infile, studentType students[])
{
	int temp;
	int counter, index;
	int length;
	length = 21;

  for (counter = 0; counter < length - 1; counter++ )
  {
	  for (index = 0; index < length - 1 - counter; index++)
		  if (students[index].testscore > students[index + 1].testscore)
		  {
			  temp = students[index].testscore;
			  students[index].testscore = students[index + 1].testscore;
			  students[index + 1].testscore = temp;
		  }

}
}

void PrintNames(ofstream& outfile, studentType students[])
{
int index;
for (index = 0; index < 20; index++)
{
outfile << left << students[index].studentLName << ", " << left << students[index].studentFName <<" "<<students[index].grade <<" "<< students[index].testscore << endl;
}
}

Alright.. I almost figured it out dude. The only problem with this is the names do not sort with the grade and one name comes up with a zero for the score...and I don't know how to fix that...at least we got something to turn in though..haha
Last edited by locomonkey : 19-Apr-2006 at 09:41. Reason: Please enclose c++ code in [c++] ... [/c++] tags
  #6  
Old 01-May-2006, 09:46
cable_guy_67's Avatar
cable_guy_67 cable_guy_67 is offline
Senior Member
 
Join Date: Oct 2004
Location: Nescopeck, PA
Posts: 1,109
cable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the rough

Re: Beginner


What is the format of Ch11_Ex1Data.txt or GradeResults.txt? Either attach the text file or describe the format of it. It would help.

Mark

BTW, locomonkey, I see you edited for the proper code tags. I do appreciate it...
__________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work."
--Thomas Alva Edison
"Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety."
--Benjamin Franklin
"A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes."
--Hugh Downs
 
 

Recent GIDBlogDeveloping GUIs with wxPython (Part 4) by crystalattice

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
C++ Beginner JYGUTI C++ Forum 2 01-Feb-2005 12:27
beginner questions fightthefuture C++ Forum 0 20-Jan-2005 02:37
Beginner to VB.NET and C#.NET theduke1997 .NET Forum 4 21-Dec-2004 18:14
Help a beginner with apache pls... seta21 Apache Web Server Forum 3 27-Nov-2004 08:27
RAID 0 -- beginner questions, need recommendation ldriskell Computer Hardware Forum 2 09-Jul-2004 19:47

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

All times are GMT -6. The time now is 07:01.


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