calculate the mortgage rate

Hello,

I've been doing this project for my computer science class but there was a problem and I don't know if it's from the server or it's in my code so please help me figure it out.

so this is the question:

You have been asked to write a program to calculate the mortgage rate for your five clients. The computation process itself can be conveniently done by a web service, as demonstrated by the following code:

#include "soapH.h" // include the generated proxy
#include <string>
#include <iostream>
#include <stdlib.h>
#include "MortgageSoap.nsmap" //include namespace map

using namespace std;

int main()
{
struct soap *soap = soap_new(); //new soap instance
_ns1__GetMortgagePayment* myData = new _ns1__GetMortgagePayment; //input class instance, determined from mortgage.h
_ns1__GetMortgagePaymentResponse* myResult = new _ns1__GetMortgagePaymentResponse; //output class instance
int theName;//years
double theName2[4];//interest, loan amount, annual tax, annual insurance


cout<<"Years: ";
cin>>theName;
cout<<"Interest: ";
cin>>theName2[0];
cout<<"Loan amount: ";
cin>>theName2[1];
cout<<"Annual tax: ";
cin>>theName2[2];
cout<<"Annual insurance: ";
cin>>theName2[3];

myData->Years=theName;
myData->Interest=theName2[0];
myData->LoanAmount=theName2[1];
myData->AnnualTax=theName2[2];
myData->AnnualInsurance=theName2[3];

if (soap_call___ns1__GetMortgagePayment(soap, NULL, NULL, myData, myResult) == 0)
{ //soap method for getting mortgage quote, determined from mortgage.h
ns1__MortgageResults* results = new ns1__MortgageResults;
results=myResult->GetMortgagePaymentResult;
cout<<"\nMonthly principal and interest: "<<
results->MonthlyPrincipalAndInterest<<"\n";
cout<<"Monthly tax: "<<results->MonthlyTax<<"\n";
cout<<"Monthly insurance: "<<results->MonthlyInsurance<<"\n";
cout<<"Total payment: "<<results->TotalPayment<<"\n";
}
else{
soap_print_fault(soap, stderr);
}
soap_destroy(soap); //destroy soap instance
system("pause");
return 0;
}


The complete project of the above code is available at VLT (gsoapMortgage.rar). Based on the above code, your program should read in the basic information from keyboard for these five clients, store the information in an array of struct, use the web service to obtain the mortgage result, and print out the mortgage information to computer screen as well as an output data file (mortgage.dat).

The struct of client information should contain the following fields:

Years (data type: int)
Interest (data type: float; unit: percentile)
Loan_amount (data type: float; unit: dollar)
Annual_tax (data type: float; unit: dollar)
Annual_insurance (data type: float; unit: dollar)

The name of the above struct is ClientInfo. The detailed information for the five clients is as follows:

Client1: Years (30), Interest (4.5), Loan_amount(300000), Annual_tax(3000), Annual_insurance(1000)

Client2: Years (15), Interest (4.5), Loan_amount(300000), Annual_tax(3000), Annual_insurance(1000)

Client3: Years (30), Interest (3.5), Loan_amount(200000), Annual_tax(2000), Annual_insurance(800)

Client4: Years (20), Interest (3.5), Loan_amount(200000), Annual_tax(2000), Annual_insurance(800)

Client5: Years (30), Interest (4.5), Loan_amount(180000), Annual_tax(2000), Annual_insurance(700)


You should create another struct for mortgage result, which contains the following fields:

MonthlyPrincipalAndInterest (data type: float)
MonthlyTax (data type: float)
MonthlyInsurance (data type: float)
TotalPayment (data type: float)

The name of the above struct is MortgageResult.



The program should have a while loop or a for loop in the main routine to ask users input the client information through keyboard. In this way, the program has a capability of repeatedly asking for the information in each loop until the information of all the five clients is provided.



this is the code I wrote:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "soapH.h"    // include the generated proxy
#include <string>
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include "MortgageSoap.nsmap" //include namespace map

using namespace std;

struct ClientInfo
{
	int year;
	float interest;
	float loan_amount;
	float annual_tax;
	float annual_insurance;
};

struct MortgageResult
{
	float MonthlyPrincipalAndInterest;
	float MonthlyTax;
	float MonthlyInsurance;
	float TotalPayment;
};

int main()
{
  struct soap *soap = soap_new();  //new soap instance
  _ns1__GetMortgagePayment* myData = new _ns1__GetMortgagePayment;  //input class instance, determined from mortgage.h
  _ns1__GetMortgagePaymentResponse* myResult = new _ns1__GetMortgagePaymentResponse; //output class instance
  int theName;//years
  double theName2[4];//interest, loan amount, annual tax, annual insurancefo

  ofstream OutFile;
  OutFile.open("mortgage.dat");




  
	ClientInfo x[100];    // store client information
	MortgageResult y[100];   // store the result of mortgage calculation
	int num_client=5;    // number of clients
	
	int i;
	for(i=0; i<num_client; i++)               // get client info.                                            
	{	
		cout << "Years: " << i++ << endl;
		cin >> x[i].year;
		cout << "Interest: ";
		cin >> x[i].interest;
		cout << "loan amount: ";
		cin >> x[i].loan_amount;
		cout << "Annual tax: ";
		cin >> x[i].annual_tax;
		cout << "Annual Insurance: ";
		cin >> x[i].annual_insurance;
	}
  
	for(i=0; i<num_client; i++)     //calculate the mortgage                    
	{
		myData -> Years = x[i].year;
		myData -> Interest = x[i].interest;
		myData -> LoanAmount = x[i].loan_amount;
		myData -> AnnualTax = x[i].annual_tax;
		myData -> AnnualInsurance = x[i].annual_insurance;
	
		if (soap_call___ns1__GetMortgagePayment(soap, NULL, NULL, myData, myResult) == 0) 
		{
			// soap method for ...
			ns1__MortgageResults* results = new ns1__MortgageResults;
			results = myResult -> GetMortgagePaymentResult;
			y[i].MonthlyPrincipalAndInterest = results->MonthlyPrincipalAndInterest;
			y[i].MonthlyTax = results -> MonthlyTax;
			y[i].MonthlyInsurance = results -> MonthlyInsurance;
			y[i].TotalPayment = results -> TotalPayment;

			OutFile << "Client # is:" << i++ << endl;
			OutFile << "\n Monthly Principal and Interest: " << y[i].MonthlyPrincipalAndInterest << endl;
			OutFile << "Monthly Tax: " << y[i].MonthlyTax << endl;
			OutFile << "Monthly Insurance: " << y[i].MonthlyInsurance << endl;		
			OutFile << "Total Payment: " << y[i].TotalPayment << endl;

			delete results;


		}

		else {
			soap_print_fault(soap, stderr);       // old, KEEP it
		}
	}

	  soap_destroy(soap); //destroy soap instance
  system("pause");
  OutFile.close();
  return 0;
}


please help me
thanks!

Edit: there are other files if you want to try to compile the code and see what's going on but I won't upload them if there is no need to do that.
Last edited on
Topic archived. No new replies allowed.