Help me if you can please ???
Got so far on my project and know gone brain dead!!
Project is for company called Zenith Paints ( please someone reconise this)

(The first program in the Visual C++ project is a validation program. You are required to validate three different types of records held on a single transaction file. Any records found to be invalid are to be written to an error report, all valid records will be written to a valid file held on disk. All the possible validation tests have been listed below.

The Record type needs to be validated on ALL records. If the record type is invalid (i.e. not ‘I’, ‘R’, ‘D’ or ‘C’) then the record should be written directly to the printed report. You may wish to test the length and break the details into the fields of the closest record type. This is acceptable but not mandatory)

Does this ring any bells with you? I have soted the structure side of the program but need to work out the modulus 11 checkdigit part next .

Any help would be top !!! :rolleyes:

I will get some notes together for you to look at, if this is ok??
I have made a transaction file as a .txt file in the format required and I have managed to get the file to read from A: into structures that I have set up in my program and I have created a union for these structures.
The part I have to do next is to validate a modulus 11 checkdigit code that is part of the customer number, I have a good idea on how the modulus checkdigit works but I just need to know the best way to get it to read into my program and validate.
If it best i can forward the code so far with all the info i ahve in txt format??

Been a long time since i started this project (other work comitments getting in the way as usual). The good news is that I have managed to get the check digit part of the program to work, But would really like some help in checking customer code.( I will give alot more infomation regarding the validation logic of this part of the code)
Please can anyone be of assistance or has anyone studied with Computeach in the UK ? if so please get in contact @ dicey75@hotmail.com
I wana pick ya brains!!!

>Does this ring any bells with you?
Of course. It's a common homework exercise and a common part of any business file processing. This is clearly homework, and you haven't shown an attempt, so the help you get will be minimal.

can you not post up code? that way we get evdience that your working and maybe an insight to your understanding too

Hi,
I have attached my program that I have been working on.
It would be good if you could tell me if I am heading in the right direction or not.
Many Thanks.

Ps File name :- Test Data File.cpp.

Attachments
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>


// Structure Definitions.

struct I_R_Record // Issue and Reciept Record
{
char type;
char cust_code[6];
char part_num[7];
char qty[5];
};

struct Cust_Record // Customer Record
{
	char type;
	char cust_code[6];
	char cust_name[21];
	char cust_address[61];
	char cust_balance[10];
	char credit_limit[8];
};

struct Delete_Record // Delete Record
{
	char type;
	char cust_code[6];
};

// Union Definition

union zenith_union{
	struct I_R_Record I_R_R;
	struct Cust_Record C_R;
	struct Delete_Record D_R;
};
union zenith_union zunion; // Union Declaration??? zunion is the declaration


// Function Prototypes:-

void open_files (fstream&in_file,fstream&prn_file,fstream&out_file);// calling by reference
bool check_digit_5(char * ptr);// cust_code prototype

void close_files (void);


// Declarations





int main()

{

fstream in_file,prn_file,out_file;

	open_files(in_file,prn_file,out_file);
	

{  

	char record[256];
      prn_file << " INVALID PREFIX. PREFIX MUST READ C,D,I,R. " <<endl
		  <<" -----------------------------------------"<<endl<<endl;

     
					 

while ( in_file.peek()!= EOF)

{	
	in_file.getline(record,256);  
	
	if(record[0] != 'D' && record[0] != 'C' && record[0] != 'I' && record[0] != 'R')
	{prn_file << record << endl;
	continue;
	}

		
if (record[0] == 'D')
	
{
	zunion.D_R.type = record[0];
	strncpy(zunion.D_R.cust_code, record + 1, 5);
	zunion.D_R.cust_code[5] = '\0';
 
	if (check_digit_5(zunion.D_R.cust_code) != true) 

		prn_file << record << endl;

	
}

		


else if (record[0] == 'C')

{
	zunion.C_R.type = record[0];
	strncpy(zunion.C_R.cust_code, record + 1, 5);
	zunion.C_R.cust_code[5] = '\0';
	strncpy(zunion.C_R.cust_name, record + 6, 20);
	zunion.C_R.cust_name[20] = '\0';
	strncpy(zunion.C_R.cust_address, record + 26, 60);
	zunion.C_R.cust_address[60] = '\0';
	strncpy(zunion.C_R.cust_balance, record + 86, 9);
	zunion.C_R.cust_balance[9] = '\0';
	strncpy(zunion.C_R.credit_limit, record + 95, 7);
	zunion.C_R.credit_limit[7] = '\0';

}

else if (record[0] == 'I' || 'R')

{
	zunion.I_R_R.type = record[0];
	strncpy(zunion.I_R_R.cust_code, record + 1, 5);
	zunion.I_R_R.cust_code[5] = '\0';
	strncpy(zunion.I_R_R.part_num, record + 6, 6);
	zunion.I_R_R.part_num [6] = '\0';
	strncpy(zunion.I_R_R.qty, record + 12, 4);
	zunion.I_R_R.qty [4] = '\0';
}

	}
}









{
	close_files();
}	

return 0;

}





// Function Definitions 

void open_files (fstream&in_file,fstream&prn_file,fstream&out_file) // Open all files for Data Read Write
{
   	// In_file = Un Validated Data
	// Prn_file = Errrors and data from Un Validated Data (in txt format)
	// Out_file = Validated Data (in txt format change to bin)
				
		

in_file.open ("A:test.txt",ios::in);
prn_file.open ("A:521113TD.txt",ios::out); // No print stream for Win XP
out_file.open ("A:521113VF.txt",ios::out);

if (!in_file.is_open()|| !prn_file.is_open()|| !out_file.is_open())
{
	cout<< endl <<" Could Not Open The Data File or Printer or Valid File "
		<< endl;
	exit(1);

}

{
  prn_file << "\t\t\t ZENITH PAINTS INVALID RECORD DETAILS . " << endl
           << "\t\t\t ************************************** " << endl<<endl;
	  
}

return;
}


bool check_digit_5(char * ptr)// Function

{
	int w1,w2,w3,w4,chk_digit5,result;
	 
	for	(int i =0; i <4; i++)
	{  
	if	(! isdigit(ptr[i]))
         
	return false;
	}

w1 = (ptr[0] - '0') * 5;
w2 = (ptr[1] - '0') * 4;
w3 = (ptr[2] - '0') * 3;
w4 = (ptr[3] - '0') * 2;

result = (w1 + w2 + w3 + w4) % 11;

result = 11 - result;

if ( result == 11)
chk_digit5 = 'X';

else

if ( result == 10)
chk_digit5 = '0';

else
	chk_digit5 = ( result + '0');


if (chk_digit5 == ptr [4])
return true;

else

return false;

}



void close_files (void) // Close all files
{
	fstream in_file,prn_file,out_file;
in_file.close();
prn_file.close();
out_file.close();
return;
}
This article has been dead for over six months. Start a new discussion instead.