You are on page 1of 19

ECSC402 Programming Methodology (C++)

Coursework 1

Module Leader: Miss. Ishara Perera


By: R.A.Thushara Kasun Ranawaka Student ID: 2010066 Group B

Coursework 1 Contents
1. 0 : Introduction .........................................................................................................page 1 1.1 : 2.0 Background

: Program SecureLife ..............................page 2 - 14 2.1 :Design(flow chart) 2.2 :Source code

2.3 : Test plan 2.3.1 : Test plan 1 2.3.2 : Test plan 2 2.4 :Test results 2.3.1 : screen shots 3.0 :Conclusion ......................................................................................page 15-17

0|Page

Coursework 1

Acknowledgment.
Thank you very much everyone who help me to deliver this program

1.0 Introduction
1.1 Background SecureLife is a new Insurance company that intents to introduce a computerized insurance system for their customers. The program read the customer details that include in a text file print it on screen and save changed detail in another text file. 1st program display a menu to choose whether to claim or get policy details. Then user should select an option (1 or2) to continue. Then user should enter the policy number to the system. After you entered policy number system validates it and finds a match. Then system displays the policy details and asks for claim amount if necessary. When you entered claim amount system check the capability of doing that transaction. If its ok system display remaining balance and save the transaction details in Claimed.txt.

1|Page

Coursework 1 2.0
2.1 Design
start

Program SecureLife

display "Menu 1)claim 2)policy detail" accept answer

display "enter policy number"

YES

Is answer==1

NO

display "enter policy number"

accept policyNum

accept policyNum read the policyData.txt file

read the policyData.txt file

Is policyNum== text data YES display "policy details"

NO

i++

Is policyNum== text data YES display "policy details"

NO

i++

display "enter claim amount"

accept claimAmount

Is (claimAmount*70/100) <text data YES value= text data-claimAmount write the value in save.txt

NO

display "do you want to continue"

accept answer2

Is answer=='y'or'Y' NO End

YES

2|Page

Coursework 1
2.2:Source code
/*Insurance system *Thushara Kasun Ranawaka *3rd may 2011 */ #include<iostream> #include<string> #include<fstream> #include<limits> #include<stdlib.h> using namespace std;

string str[320]; const float CLAIM = 0.7;

void claim(int pn) { int claimV=0,amount=0; string balance; cout<<"Enter the value to claim\t:"; cin>>claimV; while(!cin||claimV<0) { cerr<<"Invalid input!\n"; cin.clear( ); cin.ignore(numeric_limits <streamsize>::max( ),'\n'); cout<<"Re-enter the claim value(pounds)\t:"; cin>>claimV; } amount = atoi(str[pn].c_str());//converting string to an int while((amount*CLAIM)-claimV<0)//check possibility of claim { cout<<"You can't process this transaction !\nInsufficient credit\n"; cout<<"Re-enter the claim value(pounds)\t:"; cin.clear( ); cin.ignore(numeric_limits <streamsize>::max( ),'\n'); cin>>claimV; } int newPolicyAmount=amount-claimV; cout<<"The New Insured Amount(pounds)\t:"<<newPolicyAmount<<endl;

ofstream myFile("Claimed.txt",ios::app);

3|Page

Coursework 1
if (!myFile) { cout<<"Unable to open input file"; } string saveD="Name\t\tPolicy Number\tWithdraw Amount\tNew Insured Amount(pounds)\n"; myFile<<saveD<<str[pn-7]<<'\t'<<str[pn-3]<<'\t'<<amount<<"\t\t\t"<<newPolicyAmount<<'\n'; myFile.close(); } int serch(string pNum) { int i=0,pn=0; ifstream myFile("PolicyData.txt"); if (!myFile) { cout<<"Unable to open input file"; } while(!myFile.eof()) { if ((i+1)%8==0) { getline(myFile,str[i++]); } else { getline(myFile,str[i++],'\t'); } } int count2=0; for(int k=0;k<320;k++)//this is to check whether the policy number you entered right or wrong { if(str[k]!=pNum) { count2++; } } while(count2==320) { cerr<<"The Policy Number you Enter is Invalid!\n"; cout<<"Re-enter Policy Number\t:"; cin.clear( ); cin.ignore(numeric_limits <streamsize>::max( ),'\n'); cin>>pNum; count2=0; for(int k=0;k<320;k++) { if(str[k]!=pNum) { count2++; } } }

4|Page

Coursework 1
for(int j=4;j<320;j+=8) { if(str[j]==pNum) { cout<<"*****************************************************\n"; cout<<"Insurance Policy HoldersName\t:"<<str[j-4]<<endl; cout<<"Address\t\t\t\t:"<<str[j-3]<<endl; cout<<"Date of birth\t\t\t:"<<str[j-2]<<endl; cout<<"Contact Number\t\t\t:"<<str[j-1]<<endl; cout<<"Policy Number\t\t\t:"<<str[j]<<endl; cout<<"Policy Type\t\t\t:"<<str[j+1]<<endl; cout<<"Date Created\t\t\t:"<<str[j+2]<<endl; cout<<"Insured Amount(pounds)\t\t:"<<str[j+3]<<endl; cout<<"*****************************************************\n\n"; pn=j+3;//the array number of Insured Amount that belongs to above policy number break; } } return pn; myFile.close(); }

void menu() { int no=0; string pNumber=" "; cout<<"\n****************SecureLife****************\n\n"; cout<<"Menu\n"; cout<<"*******\n"; cout<<"<1> Claim\n"; cout<<"<2> Get policy details\n"; cout<<"*****************************\n"; cout<<"Your answer\t:"; cin>>no; while(!cin||no<1||no>2) { cerr<<"Invalid input!\n"; cout<<"Menu\n"; cout<<"*******\n"; cout<<"1) Claim\n"; cout<<"2) Get policy details\n"; cout<<"*****************************\n"; cout<<"Your answer\t:"; cin.clear( ); cin.ignore(numeric_limits <streamsize>::max( ),'\n'); cin>>no; } if(no==1) { cout<<"Enter Policy Number\t:"; cin>>pNumber;

5|Page

Coursework 1
cout<<endl; int pn=serch(pNumber); claim(pn); } else if(no==2) { cout<<"Enter Policy Number\t:"; cin>>pNumber; cout<<endl; serch(pNumber); } }

void main() { menu(); char answer=' '; cout<<"Do you want to continue?[y]es [n]o "; cin>>answer; cout<<"*****************************************************\n"; if(answer=='N'||answer=='n') { exit(1); } while(!cin||(answer!='y'&&answer!='Y'&&answer!='N'&&answer!='n')) { cerr<<"Invalid input!\n"; cout<<"Do you want to continue?[y]es [n]o "; cin.clear( ); cin.ignore(numeric_limits <streamsize>::max( ),'\n'); cin>>answer; cout<<"*****************************************************\n"; if(answer=='N'||answer=='n') { exit(1); } } while(answer=='y'||answer=='Y') { menu(); cout<<"Do you want to continue?[y]es [n]o "; cin.clear( ); cin.ignore(numeric_limits <streamsize>::max( ),'\n'); cin>>answer; cout<<"*****************************************************\n"; if(answer=='N'||answer=='n') { exit(1); }

6|Page

Coursework 1
while(!cin||(answer!='y'&&answer!='Y'&&answer!='N'&&answer!='n')) { cerr<<"Invalid input!\n"; cout<<"Do you want to continue?[y]es [n]o "; cin.clear( ); cin.ignore(numeric_limits <streamsize>::max( ),'\n'); cin>>answer; cout<<"*****************************************************\n"; if(answer=='N'||answer=='n') { exit(1); } } } system("pause");

2.2:Test plan of the program

2.2.1 Test plan 1 : Policy number validation


Test 1* 2 3 4 5 6 7 8 9* 10 data 999999L 100000L 100001L 100010L 100011V 100023V 100024M 100034M 100035M 100036M Expcted output Invalid input Display policy detail Display policy detail Display policy detail Display policy detail Display policy detail Display policy detail Display policy detail Display policy detail Invalid input Actual output Invalid input Display policy detail Display policy detail Display policy detail Display policy detail Display policy detail Display policy detail Display policy detail Display policy detail Invalid input ok Not ok ok ok ok ok ok ok ok ok Not ok
7|Page

Coursework 1

11 12 13 14 15* 16 17 18* 19 20

thusharaL 123456L L 100000 100000Lthushara thushara100000L L100000 100000L thushara ******L (100000L)

Invalid input Invalid input Invalid input Invalid input Invalid input Invalid input Invalid input Invalid input Invalid input Invalid input

Invalid input Invalid input Invalid input Invalid input Invalid input Invalid input Invalid input Display policy detail Invalid input Invalid input

Not ok Not ok Not ok Not ok Not ok Not ok Not ok Not ok Not ok Not ok

2.2.2 Test plan 2 : Testing claim values


Test 1 2 3 4 Data Policy Number 100000L data 525 526* 527* 0 Do the transaction display remaining balance Do the transaction display remaining balance error error Do the transaction ok display remaining balance Do the transaction ok display remaining balance error Not ok Do the transaction Not ok display remaining balance
8|Page

Expcted output Actual output ok

Coursework 1

5 6 7 8 9 10 11 12 13 14

100011V

-1000* 2209 1 2000 abc* *** 3250 3250abc* Abc3250* 100035M

100035M

error error Do the transaction display remaining balance error error error Do the transaction display remaining balance error error error

error error Do the transaction display remaining balance error error error Do the transaction display remaining balance Do the transaction display remaining balance error error

Not ok Not ok ok Not ok Not ok Not ok ok Not ok Not ok Not ok

*include the screen shot of above process


2.3:Test results
2.3.1:screen shots

9|Page

Coursework 1

10 | P a g e

Coursework 1

11 | P a g e

Coursework 1

12 | P a g e

Coursework 1

13 | P a g e

Coursework 1

14 | P a g e

Coursework 1 3.0
The problems I had face 1) How to use the fstream header? 2) How it works (getline)? 3) How to rearrange policyData.txt? 4) How to check the policy number I entered right or wrong? 5) How to convert string to an int? 6) How to save in a text file? 7) How to increase the user friendliness? 8) How does someone else understand my code or develop it?

Conclusion

How I manage them 1) I Just went to C++.com and searched details about fstream. Then I understood how to use the function. 2) Go through the lecture notes and find out the answer. 3) Contact the lecturer and asked what to do. 4) Use a while loop which include a count++ from that I found a way to validate these data. 5) I asked from some friends and hemika kodikara gave me the answer. 6) I success this task by keep on trying. Really it worked for me, I failed several times early. Latter I found the way to save the text data. 7) I tried my best to deliver a user friendly program by using simple English and adding newlines, stars, spaces,..etc. whenever it necessary. 8) I leave some comments whenever it difficult to understand & for the use of next developer.

15 | P a g e

Coursework 1
Final decision This is my 1st program that I use text file for get detail and display it and then again save the changed details (values).I had encountered many problems while developing this program. I solve many of them and gained huge experience by solving them.

I try to use many programing technics that I learn from the course. I used if/else, while/for loops, functions,etc. I use a constant, a global variable & 9 local variables in my program. In my program there is 4 functions including the main function.

Unfortunately i did not use enumeration or structures in my program. As I think its the defect of my program. I try to add them but instead of that I use a mathematical way solve them. Because of that reading ability of my coding slightly reduced. To get rid from that defect of my coding I leave some useful comments whenever it necessary.

Taking as a whole I think made a good program that can be used in the industry for commercial use.

16 | P a g e

Coursework 1
Attachments

References www.cplusplus.com

The End

17 | P a g e

You might also like