0

Hi I am writing a address book program that is giving a run time error. Please if someone can compile and check this error, and then explain/ show me how can I resolve it. I am pasting my code in parts here as well as attaching the files.

Also please someone explain me, how can I print the user input address in the main(). I mean what should my argument be for the print_add() when I call it in main().

I really appreciate your help.
Thanks.

/**********Header file*****************/
#ifndef addressType_H


#include<iostream>
#include<iomanip>
#include<string>
using namespace std;

class addressType
{
private:
	string St_address;
	string city, state;
	int Zip;

public:
	string  print_add(string, string, string, int);
	void get_add();
	void set_add(string, string, string, int);
	addressType();
	~addressType();
};
#endif

/***********************Implementation section*********/

#include "addressType.h"
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;


addressType::addressType()
{
     St_address = "9803 Summer Breeze Dr.";
	 city = "Pearland";
	  state = "Tx";
	  Zip = 77584;

}


void addressType::get_add()
{

	cout<<"Enter your street address."<<endl;
	cin>> St_address;

	cout<<"Enter your city."<<endl;
	cin>> city;

	cout<<"Enter your state."<<endl;
	cin>> state;

	cout<<"Enter your zip code."<<endl;
	cin>> Zip;
	
	set_add(St_address, city, state, Zip);

	return ;
}

void addressType::set_add(string street, string cit, string st, int zip)
{

   	St_address = street;
	city = cit;
	state = st;
	Zip = zip;

	print_add(St_address, city, state, Zip);

	return;

}

string addressType::print_add(string str, string Cit, string St, int Z)
{
	cout<<"Address: "<<endl;
	cout<< Cit <<","<<St<<endl;
	cout<<"Zip: "<<Z<<endl;

	return 0;

}

addressType::~addressType()
{}

/**************Test program********************/
// Address Directory.cpp : Defines the entry point for the console application.
//
// add_Book.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"

#include "addressType.h"
#include<iostream>
#include<string>
using namespace std;

int main()
{
	addressType Avi;
	Avi.get_add();
	Avi.print_add("9803 Summer Breeze", "Pearland", "Tx", 77584);


	return 0;
}
Attachments
#include "addressType.h"
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;


addressType::addressType()
{
     St_address = "9803 Summer Breeze Dr.";
	 city = "Pearland";
	  state = "Tx";
	  Zip = 77584;

}


void addressType::get_add()
{

	cout<<"Enter your street address."<<endl;
	cin>> St_address;

	cout<<"Enter your city."<<endl;
	cin>> city;

	cout<<"Enter your state."<<endl;
	cin>> state;

	cout<<"Enter your zip code."<<endl;
	cin>> Zip;
	
	set_add(St_address, city, state, Zip);

	return ;
}

void addressType::set_add(string street, string cit, string st, int zip)
{

   	St_address = street;
	city = cit;
	state = st;
	Zip = zip;

	print_add(St_address, city, state, Zip);

	return;

}

string addressType::print_add(string str, string Cit, string St, int Z)
{
	cout<<"Address: "<<endl;
	cout<< Cit <<","<<St<<endl;
	cout<<"Zip: "<<Z<<endl;

	return 0;

}

addressType::~addressType()
{}
#ifndef addressType_H


#include<iostream>
#include<iomanip>
#include<string>
using namespace std;

class addressType
{
private:
	string St_address;
	string city, state;
	int Zip;

public:
	string  print_add(string, string, string, int);
	void get_add();
	void set_add(string, string, string, int);
	addressType();
	~addressType();
};
#endif
// Address Directory.cpp : Defines the entry point for the console application.
//
// add_Book.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"

#include "addressType.h"
#include<iostream>
#include<string>
using namespace std;

int main()
{
	addressType Avi;
	Avi.get_add();
	//Avi.print_add("9803 Summer Breeze", "Pearland", "Tx", 77584);


	return 0;
}
1
Contributor
1
Reply
2
Views
8 Years
Discussion Span
Last Post by robgeek
0

Solved it.

I was able to solve the error.
The problem was with the return type of the print_add() function. I changed it from string to void and the error got resolved.

But this leads me to a question, which I will ask in a new thread.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.