C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 27th, 2005, 12:46 PM
klmbrt klmbrt is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Location: Russellville, AR
Posts: 2 klmbrt User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 15 sec
Reputation Power: 0
Send a message via ICQ to klmbrt Send a message via AIM to klmbrt Send a message via MSN to klmbrt Send a message via Yahoo to klmbrt
Unhappy Array or String Comparing Assignment

I am attempting to write a C++ program that has the results of a T/F test. It takes the information from a data file and then it compares the students answers to the correct answers. I have two problems. First the data file has the first 8 characters as the Student ID(Letters and Numbers), then it has a blank space followed by the student answers. Can someone give me some ideas about how I would maybe use strcmp or would I use a method of comparing Arrays?
The output would be the student ID followed by the student answers and then a Grade.
I just need help getting started in the right direction. So far my ideas have been bad...

Last edited by klmbrt : February 27th, 2005 at 12:51 PM. Reason: Revised

Reply With Quote
  #2  
Old February 27th, 2005, 04:39 PM
klmbrt klmbrt is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Location: Russellville, AR
Posts: 2 klmbrt User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 15 sec
Reputation Power: 0
Send a message via ICQ to klmbrt Send a message via AIM to klmbrt Send a message via MSN to klmbrt Send a message via Yahoo to klmbrt
Here is where I am trying to go with this, I think:
/************************************************** ***********************************



Program Filename: ch09p6.cpp

Author: Keith A. Lambert Sr.

Date Written: February 26, 2005

Assignment: Program #3

Purpose:

Input From: disk file grades.dat

Output To: screen

Functions:



************************************************** ***********************************/



/* Preprocessor Directives: ************************************************** ******/



#include <iostream>

#include <fstream>

#include <iomanip>

#include <cstring>

using namespace std;





/* Begin Main ************************************************** *********************/



int main()

{

char a[21]={'T','F','F','T','F','F','T','T','T','T','F','F',

'T','F','T','F','T','F','T','\0'};

char str[30];







ifstream inFile;

inFile.open ("grades.dat.c_str");

if (!inFile)

{

cout << "Could not open file.\n";

return 1;

}

while (inFile)

{

cin.get(str[30]);

strcpy(str, "grades.dat.c_str");

if (strcmp (a[0], str[9])<0)

{

cout << strcmp;

}

cout << str[0,1,2,3,4,5,6,7] << endl;

}



inFile.close();

return 0;

}

An example of the input file would be:

ABC54301 TFTFTFTT TFTFTFFTTFT

notice that one question would be unanswered in this example and the input starts with the Student ID and seperated only by a space.



Reply With Quote
  #3  
Old February 28th, 2005, 02:12 PM
Viper_SB's Avatar
Viper_SB Viper_SB is offline
Moderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Canada
Posts: 331 Viper_SB User rank is Private First Class (20 - 50 Reputation Level)Viper_SB User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 4 h 53 m 7 sec
Reputation Power: 6
I was going to edit your post and put code tags around your code but I see way to many font and size tags . anyways use code tags next time it makes it very easy to read that way and keeps formatting. moved to C/C++ forum

Reply With Quote
  #4  
Old February 28th, 2005, 02:26 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
I took the liberty to indent the code, and strip the font tags...
Code:
/**************************************************  ***********************************

Program Filename: ch09p6.cpp
Author: Keith A. Lambert Sr.
Date Written: February 26, 2005
Assignment: Program #3
Purpose:
Input From: disk file grades.dat
Output To: screen
Functions:

**************************************************  ***********************************/

/* Preprocessor Directives: **************************************************  ******/

#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstring>
using namespace std;


/* Begin Main **************************************************  *********************/

int main()
{
	char a[21]={'T','F','F','T','F','F','T','T','T','T','F','F',  
	            'T','F','T','F','T','F','T','\0'};
	char str[30];

	ifstream inFile;
	inFile.open ("grades.dat.c_str");

	if (!inFile)
	{
		cout << "Could not open file.\n";
		return 1;
	}

	while (inFile)
	{
		cin.get(str[30]);
		strcpy(str, "grades.dat.c_str");
		if (strcmp (a[0], str[9])<0)
		{
			cout << strcmp;
		}
		cout << str[0,1,2,3,4,5,6,7] << endl;
	}

	inFile.close();
	return 0;
}
klmbrt: What does an input file look like?
And I don't quite understand what the output represents...

Reply With Quote
  #5  
Old February 28th, 2005, 03:46 PM
Anibal Anibal is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 176 Anibal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 20 m 48 sec
Reputation Power: 4
Thanks MadCowDzz...it was incomprehensible the other way (I apologise for my terrible spelling)

use a char *answers and asign it a strtok(<input>," ").
Afterwards, just do a

Code:
 
for (i = 0; i < <number of answers>; i++) 
	if(answers[i] == arrayOfCorrectAnswers[i])
		rightOnes++;



and acumulate the rigth answers to write down the grade after the cycle is over. I think that's all...if I'm not mistaken and understood correctly!!

Good Luck...

Anibal.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Array or String Comparing Assignment


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT