esesili 0 Light Poster

Both of them are free c++ compilers. I do not know if one of them has technical advantage over the other one. If I were you I would use the one which has more documentation on the internet.

esesili 0 Light Poster

I know that anyone does not necessarily has to check my program that's why I start my question with "could you". By the way, I appreciate for your helps.

esesili 0 Light Poster

Thank for the tutorial. I succeeded what I want. However, I have one more question. If I want to see the 3rd line in the file what I have to do? By the way, could you please check the program and give me some feedback?
I appreciate for helps,

#pragma endregion
		
	private: System::Void open_file_button_Click(System::Object^  sender, System::EventArgs^  e)
			 {
	  String ^ file_name;
	  String ^ input;
      OpenFileDialog ^ openFileDialog1 = gcnew OpenFileDialog();
      openFileDialog1->Filter = "Text Files|*.txt";
      openFileDialog1->Title = "Select the File";

      
      if (openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
      {
		  file_name = System::IO::Path::GetFullPath(openFileDialog1->FileName);
		  StreamReader^ sr = File::OpenText(file_name);
		  double number_file;
		  double initial = 0;
		  double summ;
		  String ^ result;
		  while((input=sr->ReadLine())!=nullptr)
		  {
			  number_file = Convert::ToDouble(input);
			  summ = initial + number_file;
			  initial = summ;
		  }
		  result = Convert::ToString(initial);
		  System::Windows::Forms::MessageBox::Show(result,L"test",System::Windows::Forms::MessageBoxButtons::OK);
		 
	  }
			 }
esesili 0 Light Poster

Hello all,
I want to write a qui program which opens and reads a text file when pressed Open File button. So far, when I click the button Open File Dialog works and I can choose the file to read but I do not know how to read it line by line. The code for click event is below. Can you please tell me what is the next step?

#pragma endregion
	private: System::Void open_file_button_Click(System::Object^  sender, System::EventArgs^  e) {
	//we use OpenFileDialog to show a file-open dialog box
      OpenFileDialog ^ openFileDialog1 = gcnew OpenFileDialog();
      openFileDialog1->Filter = "Text Files|*.txt";
      openFileDialog1->Title = "Select the File";

      // Show the Dialog.
      
      if (openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
      {
      // pop up a message box if user selects a file               System::Windows::Forms::MessageBox::Show(L"deneme",L"test",System::Windows::Forms::MessageBoxButtons::OK);
      }
			 }
esesili 0 Light Poster

I just figured out that Intellisense is not supproted in VS 2010. That is the problem. I think I will have to install VS2008.

esesili 0 Light Poster

Yes it is a CLR. As a starting point I tried to write a simple GUI for factorial calculation. My code is shown below. When I type codes I need see what other options after :: . I also included headers as shown in the code.

#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <tchar.h>
#pragma once

namespace fact_deneme {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for Form1
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::TextBox^  number_ent;
	protected: 
	private: System::Windows::Forms::Button^  calculate;
	private: System::Windows::Forms::Label^  the_result;

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->number_ent = (gcnew System::Windows::Forms::TextBox());
			this->calculate = (gcnew System::Windows::Forms::Button());
			this->the_result = (gcnew System::Windows::Forms::Label());
			this->SuspendLayout();
			// 
			// number_ent
			// 
			this->number_ent->Location = System::Drawing::Point(21, 23);
			this->number_ent->Name = L"number_ent";
			this->number_ent->Size = System::Drawing::Size(69, 20);
			this->number_ent->TabIndex = 0;
			// 
			// calculate
			// 
			this->calculate->Location = System::Drawing::Point(27, 64);
			this->calculate->Name = L"calculate";
			this->calculate->Size = System::Drawing::Size(86, 24);
			this->calculate->TabIndex = 1;
			this->calculate->Text = L"Calculate";
			this->calculate->UseVisualStyleBackColor = true;
			this->calculate->Click += gcnew System::EventHandler(this, &Form1::calculate_Click);
			// 
			// the_result
			// 
			this->the_result->AutoSize = true; …
esesili 0 Light Poster

Hello All,
Currently I am working on an GUI using a tutorial video. In video when tutor types n = System::Convert:: , after :: a bunch of options appear like n = System::Convert::ToInt32. However, when I type same phrase n = System::Convert:: after :: no option appears. How can I activate the program to see these options after :: ?

Thank for helps,

esesili 0 Light Poster

Here is another factorial program. Almost same with others

#include <iostream>
using namespace std;
int main()
{
	long double n;
	long double result = 1;
	int k;
	cout << "please enter a non-negative number"<< endl;
	cin>> n;
	if (n<0)
	{
		cout<<"the number is less then 0."<< endl;
		cout<<"please enter a non-negative number" << endl;
		cin>>n;
		for (k = 2; k<=n; k++)
			result = result*k;
	}
	else
	{
		for (k = 2; k<=n; k++)
			result = result*k;
		
	}
esesili 0 Light Poster

Hello All,

I have been using c++ console applications for a while. I need to develop some graphical user interfaces. Even though there are many ways of developing a gui, I am not sure what is the most easy to learn and use. There is a library called Q4 library, do you suggest to use it or do you suggest something else?
I am looking forward to hearing from you,

Thanks for helps,

esesili 0 Light Poster

Hi All,
When I try to compile the code below, I get error message " error: ‘MAX_IMG_HEIGHT’ undeclared here (not in a function)". I tried to declare them in different ways but it does not work. Does anyone have idea ?
I appreciate for helps,

The code is:

/* ImagExper.h 

   - miscellaneous structure header file for ImagExpert software package   */



/* image processing range deifnition */



#define top_left_x 20

#define top_left_y 280

#define bottom_right_x 460

#define bottom_right_y 500



/* edge element gradient magnititue and direction */


//extern const int MAX_IMG_HEIGHT;
//extern const int MAX_IMG_WIDTH;

unsigned char img_edg_mag[MAX_IMG_HEIGHT][MAX_IMG_WIDTH];

unsigned char img_edg_dir[MAX_IMG_HEIGHT][MAX_IMG_WIDTH];



/* External variables for hough transfer function */



/*#define PI 3.1415926*/



struct edge {                            /* edge struct pointer */

          int xcord;  int ycord;

          unsigned char edgv;            /* grey level or gradient */

          int edsi;                      /* 360 degree */

          };



struct peak_point{                       /* hough space peak point */

          int sita;

          int rota;

          int ctva;

          };





/* Functions for Hough transfer */



void edsobl(int k, unsigned char* pie0,int ixsa,int iysa,int ixea,int iyea,

            int ity,int thres_gr);

void thingr(int k,unsigned char *pie0,int ixsa,int iysa,int ixea,int iyea,

            long int *nu_edge);

void edggen(int k,unsigned char *pie0,int ixsa,int iysa,int ixea,int iyea,

       struct edge *pedge0);

void edhou1(int k,struct edge *pedge0,long int nu_edge,

       int ixsa,int iysa,int ixea,int iyea,int *ixs_next,int *iys_next);



void hlndsp(int k, float deta_ro,float deta_si,float roc,int ix,int iy,

            float x0,float y0,int ixsa,int iysa,int ixea,int iyea,

            struct peak_point *peakpt0,long int nu_peakpt,

            int *ixs_next,int *iys_next);



void pkptds(int *ht0,int ia,int ir,struct peak_point *peakpt0,

            long int *nu_peakpt);

void …
esesili 0 Light Poster

Hi All,

I got a program which was written in c++ for unix at 1999. There are almost a hundred of source code files and makefile is available also. I do not have access to unix because of this, I need to get it worked in windows. My question is how can I convert it to windows or how can I get it worked? By the way, there is not a project file.
Thanks,

esesili 0 Light Poster

Dear All,
First of all, I do not know if this is the correct place or not but I am having problems about playing video by using opencv. I am trying to play an .avi video. I did exactly the same thing as tutorial but the code below does not work. Video and source code are in the same folder. Even though program is built successfully, it can not play the video.
Can someone please help me ?
I appreciate for helps,

#include <cv.h>
#include <highgui.h>
int main()
{
	cvNamedWindow( "Example2", CV_WINDOW_AUTOSIZE );
	CvCapture* capture = cvCreateFileCapture( "MGC_RC_ATV.avi" );
	IplImage* frame;
	while(1) {
		frame = cvQueryFrame( capture );
		if( !frame ) break;
		cvShowImage( "Example2", frame );
		char c = cvWaitKey(33);
		if( c == 27 ) break;
	}
	cvReleaseCapture( &capture );
	cvDestroyWindow( "Example2" );
	return 0;	
}
esesili 0 Light Poster

Thanks for helps. Can you tell me how can I fix it?

esesili 0 Light Poster

Hi all,
I am having problem about file operations. There are a few numbers in my txt file. I want the program to calculate average of these numbers in the txt file. The code I have written is as below. Number of numbers in the file is 5. When I return count it returns 5 .The sum of numbers should be 92 but I get 94, and I get average 18.8 but the correct average should be 18,4 (txt file is attached). So can anyone help me about it? Do you think is it a good idea to calculate it in this way?
Thanks

the code:

int main()
{
	ifstream fin;	
	fin.open("numbers.txt");
	if (fin.fail())
	{
		cout << "erorr on opening the file \n";
		exit (1);
	}
	cout << "the caculated average is  " << avg_file(fin) << endl;	
	double calculated_avg = avg_file(fin);	
}
double avg_file(ifstream& source_file)
{
	double number_in_file;
	double total = 0;
	int count = 0;
	source_file >> number_in_file;
	while (! source_file.eof())
	{		
		source_file >> number_in_file;
		total = number_in_file + total;
		count ++;
	}	
	//average of numbers in file
	return (count);	
}
esesili 0 Light Poster

Hi all,

I am trying to read double numbers from a txt file and calculate average and standard deviation. It builds successfully but gives an error when it is run. The error I see on the screen is -1.#IND. Do you have any idea what it is and how can I correct it ?
I appreciate for helps,

My code is :

double avg_file(ifstream& source_file)
{
	double number_in_file;
	double total = 0;
	int count = 0;
	source_file >> number_in_file;
	while (! source_file.eof())
	{
		total = number_in_file + total;
		source_file >> number_in_file;
		count ++;
	}
	//average of numbers in file
	return (total/count);
}

double std_dev (ifstream& in_file, double average)
{
	double number_in_file;
	double std_dev_f;
	double sum_diff = 0;
	int count = 0;
	in_file >> number_in_file;
	while (! in_file.eof())
	{
		sum_diff = pow((average-number_in_file),2)+ sum_diff;
		count++;
	}
	std_dev_f =sqrt(sum_diff/count); 
	return (std_dev_f);
}
int main()
{
	ifstream fin;
	//ofstream fout;
	fin.open("numbers.txt");
	if (fin.fail())
	{
		cout << "erorr on opening the file \n";
		exit (1);
	}
	cout << "the calculated average is  " << avg_file(fin) << endl;	
	cout << "the std devitation is     "  << std_dev(fin,avg_file(fin)) << endl;
}
esesili 0 Light Poster

Hi Sky Diplloma,

It is great idea. However, I am a beginner and I have no idea about how to do that? In this case do I have to have a Dcotor class? If I have to I do not know how to implement it. How can I generate such a list and use it to solve my problem?
Thanks,

esesili 0 Light Poster

Dear Dave,
Thank you very much for your comments. I tried it again but not get it yet. Can you please explain it more explicitly?
Thanks,

esesili 0 Light Poster

Hi all,
I want the program below to calculate the doctor fee. I am doing it to learn class and inheritance concept. "patient1.output(cout);" works correctly it gets doctor_hour_fee from doct1 object. The problem is at patient2.output(cout);. When I enter patient information it asks me to enter all member variables of doctor object and it creates a new doctor, so that doct1 and new doctor are different and normally I get wrong answer. Can you tell me how can I get doctor_hour_fee of doct1 for patient2? During input of patient2 I just want to enter name of doctor, which is doctorfirst in this case, and calculate doctor fee.
Thanks for helps,

The code listing:

#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
class Person
{
public:
	Person();
	Person(string name_of_person);
	Person(const Person &p);
	~Person();
	string get_name()const;	
	void set_name(string name_ofp);	
	void input(istream &inp);
	void output(ostream &outp);
protected:
	string name;	
};
class Doctor: public Person
{
public:
	Doctor();
	Doctor(string name_of_doctor, double hour_fee_of_doc);
	Doctor(const Doctor &d);
	~Doctor();
	double get_fee_of_doc() const;	
	void set_fee_of_doc(double hour_fee);	
	void input(istream &ind);
	friend istream& operator>>(istream &ind_try, Doctor &d);
	void output(ostream &outd);
protected:
	double doctor_hour_fee;	
};
class Patient: public Person
{
public:
	Patient();
	Patient(string name_of_patient, double visit_duration_ofp, Doctor &doc);
	Patient(const Patient &p);
	~Patient();
	double get_visit_duration() const;	
	void set_visit_duration(double visit_duration_ofp);
	void setDoctor(Doctor &doc);
	virtual double billing() const;
	void input(istream &inpa);
	void output(ostream &outpa);	
protected:
	double visit_duration;
	Doctor doctor;
};
int main()
{
	Person person1("first last");
	person1.output(cout);
	Person person2;
	person2.input(cin);
	person2.output(cout);
	Doctor doct1("doctorfirst",250);
	doct1.output(cout);
	Patient patient1("firstpatient",0.1,doct1);
	patient1.output(cout);
	Patient patient2; …
esesili 0 Light Poster

Hi all,

I have a simple question. I am working on it for a long time and I feel that I am almost done except for a small problem.
As seen below there is a member function of patient class. It takes variables name and visit_duration. In addition to these variables I want user to be able to enter doctor. This version works but user can not enter doctor.

void Patient::input(istream &inpa)
{
	cout << endl;
	cout << "Please enter information of patient(name--visit duration--Doctor)" << endl;
	inpa >> name >> visit_duration;
}

When I define this function as below it gives me the error message " error C2679:"

My all code is shown as below and I attached it also. Can you tell me please how can I include doctor object to input member function?
I appreciate for helps

Code listing:

#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
class Person
{
public:
	Person();
	Person(string name_of_person);
	Person(const Person &p);
	~Person();
	string get_name()const;	
	void set_name(string name_ofp);	
	void input(istream &inp);
	void output(ostream &outp);
protected:
	string name;	
};
class Doctor: public Person
{
public:
	Doctor();
	Doctor(string name_of_doctor, double hour_fee_of_doc);
	Doctor(const Doctor &d);
	~Doctor();
	double get_fee_of_doc() const;	
	void set_fee_of_doc(double hour_fee);	
	void input(istream &ind);
	void output(ostream &outd);
protected:
	double doctor_hour_fee;	
};
class Patient: public Person
{
public:
	Patient();
	Patient(string name_of_patient, double visit_duration_ofp, Doctor &doc);
	Patient(const Patient &p);
	~Patient();
	double get_visit_duration() const;	
	void set_visit_duration(double visit_duration_ofp);
	void setDoctor(Doctor &doc);
	virtual double billing() const;
	void input(istream &inpa);
	void output(ostream &outpa); …
esesili 0 Light Poster

When I compile the code below it generates more than 30 syntax errors. It does not make sense. The problem is probably somewhere in

Patient(string name_of_patient, int age_of_patient, string address_of_pat, double visit_duration_ofp, string ssn_of_patient, Doctor &doc);

but I could not figure out the problem.
I know it is not convenient to post all the code but I think it will be helpful. Alsoi I attached the cpp file
The code is below:

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

class Person
{
public:
	Person();
	Person(string name_of_person, int age_of_person, string address_of_person);
	Person(const Person &p);
	~Person();
	string get_name()const;
	string get_address() const;
	int get_age()const ;
	void set_address(string address_ofp);
	void set_name(string name_ofp);
	void set_age(int age_ofp);
	void input(istream &inp);
	void output(ostream &outp);
protected:
	string name;
	string address;
	int age;
};

class Patient: public Person
{
public:
	Patient();
	Patient(string name_of_patient, int age_of_patient, string address_of_pat, double visit_duration_ofp, string ssn_of_patient, Doctor &doc);
	Patient(const Patient &p);
	~Patient();
	double get_visit_duration() const;
	string get_ssn() const;	
	void set_ssn_(string ssn_ofp);
	void set_visit_duration(double visit_duration_ofp);
	
	void setDoctor(Doctor & doc)
	virtual double billing() const;
	void input(istream &inpa);
	void output(ostream &outpa);
	
protected:
	double visit_duration;
	string ssn;
	Doctor doctor;
};
class Doctor: public Person
{
public:
	Doctor();
	Doctor(string name_of_doctor,int age_of_doctor, string add_of_doctor, double hour_fee_of_doc, long reg_number, string specialty);
	Doctor(const Doctor &d);
	~Doctor();
	double get_fee_of_doc() const;
	long get_regnum_of_doc() const;
	string get_spec_of_doc() const;
	void set_spec_of_doc(string specialty);
	void set_fee_of_doc(double hour_fee);
	void set_regnum_of_doc(long reg_num);
	void input(istream &ind);
	void output(ostream &outd);
protected:
	double doctor_hour_fee;
	long doctor_reg_num;
	string spacialty;
};
int main()
{
	Doctor doctor1("ali",21,"deneadres",100,123333,"kalp");	
	//doctor1.input(cin);
	doctor1.output(cout);
	Patient …
esesili 0 Light Poster

Hi NathanOliver,

Thank you very much for your advice. It makes sense. I tried it but I got more that 30 syntax errors. I checked them but does not make sense.
Do you have any idea?
Thanks,

esesili 0 Light Poster

Hi everyone,
I have a problem about inheritance and I can not solve it since Monday. I have two classes (Student_Patient and Emp_Patient) inherited from Patient class. Patient class and Doctor classes are inherited from Person class. The Doctor class has a member functiondouble get_fee_of_doc() const; which returns a double value and Patient class has virtual double billing() const; member function. I am trying to use the double value returned from double get_fee_of_doc() const; in virtual double billing() const; . I tried to do it by two different but I could not do it. Can someone please tell me (by providing an example) what is the possible and best way of using the double value which is returned from Doctor in Patient class. Required codes are below.
By the way, sorry for convenience because it is a very long post.
I appreciate for helps.

Declaration of Doctor and Patient:

class Patient: public Person
{
public:
	Patient();
	Patient(string name_of_patient, int age_of_patient, string address_of_pat, double visit_duration_ofp, string ssn_of_patient);
	Patient(const Patient &p);
	~Patient();
	double get_visit_duration() const;
	string get_ssn() const;	
	void set_ssn_(string ssn_ofp);
	void set_visit_duration(double visit_duration_ofp);
	virtual double billing() const;
	void input(istream &inpa);
	void output(ostream &outpa);
	
protected:
	double visit_duration;
	string ssn;
	//double set_doc_fee;
};
class Doctor: public Person
{
public:
	Doctor();
	Doctor(string name_of_doctor,int age_of_doctor, string add_of_doctor, double hour_fee_of_doc, long reg_number, string specialty);
	Doctor(const Doctor &d);
	~Doctor();
	double get_fee_of_doc() const;
	long get_regnum_of_doc() const;
	string get_spec_of_doc() const;
	void set_spec_of_doc(string specialty);
	void set_fee_of_doc(double hour_fee);
	void set_regnum_of_doc(long reg_num);
	void input(istream &ind);
	void output(ostream …
esesili 0 Light Poster

I have doctor class and patient class, these two of them are inherited from person class. The doctor class has a member function "double get_fee_of_doc() const;" it returns a double value. I want to use this double value in a member function of patient class to make a very simple calculation. So my question is how can I call or use the value returned from double get_fee_of_doc() const;? If this information is not enough please let me know to post a portion of codes.
Thanks a lot,

esesili 0 Light Poster

Hi all,

I have two classes C and D these classes are inherited from B class. My question is how can I use a member function of C at D and at D's child classes? I tried to do it with a regular function but it does not work in class definitions. I also tried friends and it does not work. If you can provide your reply with an example I will be grateful.
I appreciate for helps,

Thanks,

esesili 0 Light Poster

I made it static static double get_fee_of_doc(); but it still does not work the error message is error C2597: illegal reference to non-static member 'Doctor::doctor_hour_fee'.Still I did not figure out how to pass fee to other functions.
Do you have any idea?

esesili 0 Light Poster

Thank you very much for your explanation but I did not understand exactly. By the way I assume that there is only one doctor and fee will be entered by input function. I just want to use fee of the doctor in other functions.

esesili 0 Light Poster

Hi All,
I have created a class person and derived patient and doctor classes from person. Also I derived student_patient and emp_patient classes from patient class. I want to make a small calculation at patient, student_patient and emp_patient classes by using a function from doctor class wihch is get_fee_of_doc. I call get_fee_of_doc at other classes but I get errorC2352 . I tried to find the solution on the internet but I could not.
Can you please help me about this problem?
I appreciate for helps

Here declaration of classes:

class Patient: public Person
{
public:
	Patient();
	Patient(string name_of_patient, int age_of_patient, string address_of_pat, double visit_duration, string ssn_of_patient);
	Patient(const Patient &p);
	~Patient();
	double get_visit_duration() const;
	string get_ssn() const;
	void set_ssn_(string ssn_ofp);
	void set_visit_duration(double visit_duration_ofp);
	virtual double billing() const;
	void input(istream &inpa);
	void output(ostream &outpa);
protected:
	double visit_duration;
	string ssn;
};
class Doctor: public Person
{
public:
	Doctor();
	Doctor(string name_of_doctor, double hour_fee_of_doc, long reg_number, string specialty);
	Doctor(const Doctor &d);
	~Doctor();
	double get_fee_of_doc() const;
	long get_regnum_of_doc() const;
	string get_spec_of_doc() const;
	void set_spec_of_doc(string specialty);
	void set_fee_of_doc(double hour_fee);
	void set_regnum_of_doc(long reg_num);
protected:
	double doctor_hour_fee;
	long doctor_reg_num;
	string spacialty;
};
class Student_Patient: public Patient
{
	Student_Patient();
	Student_Patient(string name_of_student, int age_of_student, string address_of_student, double visit_of_stud, string ssn_of_student, string collage_of_student);
	Student_Patient(const Student_Patient &s);
	~Student_Patient();
	string get_collage_of_stud() const;	
	void set_collage_of_student(string collage_ofs);	
	virtual double billing() const;
	void input(istream &ins);
	void output(ostream &outs);
protected:
	string collage;
	
};
class Emp_Patient: public Patient
{
	Emp_Patient();
	Emp_Patient(string name_of_emp, int age_of_emp, string address_of_emp, double visit_of_emp, string ssn_of_emp, string department_of_emp);
	~Emp_Patient();
	string …
esesili 0 Light Poster

Hello all,

I have a base class which is called person. I derived a class from person which is called patient. My question is can I derive two more classes (patient_student and patient employee) from derived class patient or should I derive them from person? If I can derive classes from derived classes how can I do that?

Appreciate for helps,

esesili 0 Light Poster

Hello All,
I am a new user of c++. Until now I just worked on basic console applications. I have to develop a program which will be able read two images and open them in separate windows and do some geometric calculations background. Also this program should allow user to perform zoom in and zoom out operations. And also when user clicks a particular pixel on the image the program should give information about that pixel. After a brief explanation of the program, my question is, what would be the best starting point for GUI at c++? I checked some predefined libraries like QT but I do not know what to do exactly. Could you please give me suggestions about this issue? By the way I am using visual studio 2005. I have a little experience on VB and it is easy to create interface with that (just drag and drop), is it same at c++? I appreciate for helps,

Thank you

esesili 0 Light Poster

Hi all,

I am studying c++ and there is an expression that i did not understand can someone please explain it to me ? It is declaration of a public class method. The expression is bool less_than(const Date &d) const . name of the class is Date.
Thank you,

esesili 0 Light Poster

Hi everyone,

I am trying to sort array by a function. My code is shown below. I get error message "runtime check failure 2 stack around the variable "arrayim"". Can someone tell me what does it mean and how to solve this problem?

I appreciate for helps

#include <iostream>
using std::cin;
using std::cout;
using std::endl;
void sort_array(int uns_array[], int length);
int main()
{
	int arrayim[3] = {77,56,1};
	sort_array(arrayim,3);
	for (int j = 0; j<3; j++)
	{
		cout << "sorted array" << arrayim[j] <<endl;
	}
}
void sort_array(int uns_array[], int length)
{
	int temp;
	for (int t = 1; t<length; t++)
	{
		for (int k =0; k<=length-1; k++)
		{
			if (uns_array[k+1]<uns_array[k])
			{
				temp = uns_array[k];
				uns_array[k]=uns_array[k+1];
				uns_array[k+1] = temp;
			}
		}
	}

}
esesili 0 Light Poster

Hello again,

I am trying to generate an array which has random integers. Then I have to sort it and perform binary search. Below is my code so far. It gives error message (runtime check failure 2 stack around the variable num_arry was corrupted). When I define num_arry[10] instead of 9 it works. However, my array should have 10 elements but it works when defined it with 11 elements. Do you have any idea about it? Should I use reference or pointer for this task?
Thanks

#include <iostream>
#include <ctime>
using namespace std;
void generate_array(int f_array[]);
void print_array(int p_array[]);

int main()
{		
	int num_arry[9];
	generate_array(num_arry);	
	print_array(num_arry);	
}

void generate_array(int f_array[])
{
	srand((unsigned)time(0));
	for (int index = 0; index<10; index++)
	{
		f_array[index]=(rand()%1000)+1;
	}
}
void print_array(int p_array[])
{
	for(int i = 0; i<10; i++)
	{
		cout << "numbers  " << p_array[i] << endl;
	}
}
esesili 0 Light Poster

Dear csurfer, I appreciate for your help,it works now. By the way, how can I do it with "call by reference" method? Some friends claim that "call by reference" is better. Do you have any suggestion about "call by reference" ? What is the advantage of "call by reference" ?
Thanks

esesili 0 Light Poster

Hello All,

I am trying to generate an array which has random integers and pass this array to a function to be able to print random integers. The code I have written is as below. Can you help me about that?
Thanks

#include <iostream>
#include <ctime>
using namespace std;
void generate_array(int& f_array[]);
void print_array(int& p_array[]);
int main()
{	
	int num_arry[4];
	generate_array(num_arry);
	print_array(num_arry);

	/*srand((unsigned)time(0)); 
    int random_integer; 
	for(int index=0; index<5; index++){ 
        random_integer = (rand()%1000)+1; 
        cout << random_integer << endl; 
    } 
	*/
}

void generate_array(int& f_array[])
{
	srand((unsigned)time(0));
	for (int index = 0; index<5; index++)
	{
		f_array[index]=(rand()%1000)+1;
	}
}
void print_array(int& p_array[])
{
	for(int i = 0; i<5; i++)
	{
		cout << "numbers" << p_array[i] << endl;
	}
}
esesili 0 Light Poster

You managed to make the try catch block. Now all you have to do is System.out.println(variable nexocentric told you to output). Debugging is a very important part of programming, so you need to learn to do it. Debugging tools are very helpful, but I personally prefer print statements. If you put them in appropriate places, such as when you read a value into a variable, after a calculation is done on a variable, etc, then you will find your problem. Basically find the key points, logically determine what the value of the variables should be at those points, and use the print statements to see if they actually are.

Hi BestJewSinceJC,
I put three System.out.println to see what is gong on. The result is

input = 
latitude = 0.0

It does not matter what I enter for textfield I alwys get same result. My code is below. Do you have any idea ?
thanks for helps,

package converter;

import javax.swing.*;
import java.awt.*;
public class ValuePanel extends JPanel {
    private JLabel valLabel;
    private JTextField valTextField;
    public ValuePanel()
    {
        setLayout(new GridLayout(1,2));
        valLabel = new JLabel("Enter Latitude");
        valTextField = new JTextField(10);
        //valTextField.setText("0");
        setBorder(BorderFactory.createTitledBorder("Latitude"));
        add(valLabel);
        add(valTextField);
    }

        public double getLatEntered()
        {
            //valTextField.setText("0");
            String input;
            double latitude;
            input = valTextField.getText();
            System.out.println("input = " + input);
            try{
                latitude = Double.parseDouble(input);
                System.out.println("latitude = " + latitude);
            }
            catch (Exception E){
                latitude = 0.0;
            }
            System.out.println("latitude = " + latitude);
            return latitude;

        }
}
esesili 0 Light Poster

Were you able to find out what's happening to the variable "input" by outputting it's value in the try catch block? Also if possible could you post the rest of your code so I can run it over here and check it really quick?

Dear nexocentric,
Sorry for this but I am new to programming this is my first application and ı could not do it. I have four class files for this simple program;

1st :Name of the file is ValuePanel.java

package converter;

import javax.swing.*;
import java.awt.*;
public class ValuePanel extends JPanel {
    private JLabel valLabel;
    private JTextField valTextField;
    public ValuePanel()
    {
        setLayout(new GridLayout(1,2));
        valLabel = new JLabel("Enter Latitude");
        valTextField = new JTextField(10);        
        setBorder(BorderFactory.createTitledBorder("Latitude"));
        add(valLabel);
        add(valTextField);
    }

        public double getLatEntered()
        {
            //valTextField.setText("0");
            String input;
            double latitude;
            input = valTextField.getText();
            try{
                latitude = Double.parseDouble(input);
            }
            catch (Exception E){
                latitude = 0.0;
            }

            return latitude;

        }
}

2nd : Name of the file is :ConverterButtons.java

package converter;

import javax.swing.*;
import java.awt.*;

public class ConverterButtons extends JPanel {
    private ValuePanel velugir;
    private JRadioButton fromGeodetic;
    private JRadioButton fromGeodesic;
    private JRadioButton fromReduced;
    private JRadioButton toGeodetic;
    private JRadioButton toGeodesic;
    private JRadioButton toReduced;
    private ButtonGroup bgFrom;
    private ButtonGroup bgTo;

    public ConverterButtons(){
        setLayout(new GridLayout(3,2));
        fromGeodetic = new JRadioButton("Geodetic",true);
        fromGeodesic = new JRadioButton("Geodesic");
        fromReduced = new JRadioButton("Reduced");
        toGeodetic = new JRadioButton("Geodetic");
        toGeodesic = new JRadioButton("Geodesic",true);
        toReduced = new JRadioButton("Reduced");
        bgFrom = new ButtonGroup();
        bgFrom.add(fromGeodetic);
        bgFrom.add(fromGeodesic);
        bgFrom.add(fromReduced);
        bgTo = new ButtonGroup();
        bgTo.add(toGeodetic);
        bgTo.add(toGeodesic);
        bgTo.add(toReduced);
        setBorder(BorderFactory.createTitledBorder("Convert From - To"));
        add(fromGeodetic);
        add(toGeodetic);
        add(fromGeodesic);
        add(toGeodesic);
        add(fromReduced); …
esesili 0 Light Poster

I assume that when you ran the code after you set the text with setText it ran just fine? A really quick way to debug this code would be to use a try catch block to find out what is going on when you parse your string.

public double getLatEntered()
{
	//valTextField.setText("0");
	String input;
	double latitude;
	input = valTextField.getText();
	try {
		latitude = Double.parseDouble(input);
	}
	catch ( Exception E ) {
		//find a place to out put the variable input
		//so you can see what the value is here
		latitude = 0.0;
	}
	
	return latitude;
	
}

Hi nexocentric,

Thank you very much for your help. When I ran the program it always returns 0.0 I enter different values but it only returns 0.0 so do you have any idea about the solution?
Thank you,

esesili 0 Light Poster

Hi all,
I am trying to write a simple program but I am having an error message that I am working on it for three days. The aim of program is to convert entered value depending on the clicked radio buttons. Please can someone help me about it ?
Thanks,

The error message is as below:

Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: empty String
        at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:994)
        at java.lang.Double.parseDouble(Double.java:510)
        at converter.ValuePanel.getLatEntered(ValuePanel.java:29)
        at converter.ConverterButtons.GetResult(ConverterButtons.java:46)
        at converter.ConvertGUI$CalcButtonListener.actionPerformed(ConvertGUI.java:47)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
        at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
        at java.awt.Component.processMouseEvent(Component.java:6216)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
        at java.awt.Component.processEvent(Component.java:5981)
        at java.awt.Container.processEvent(Container.java:2041)
        at java.awt.Component.dispatchEventImpl(Component.java:4583)
        at java.awt.Container.dispatchEventImpl(Container.java:2099)
        at java.awt.Component.dispatchEvent(Component.java:4413)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4556)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4220)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4150)
        at java.awt.Container.dispatchEventImpl(Container.java:2085)
        at java.awt.Window.dispatchEventImpl(Window.java:2475)
        at java.awt.Component.dispatchEvent(Component.java:4413)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

Here is the code for Double.java:510:

package converter;
import javax.swing.*;
import java.awt.*;
public class ValuePanel extends JPanel {
    private JLabel valLabel;
    private JTextField valTextField;
    public ValuePanel()
    {
        setLayout(new GridLayout(1,2));
        valLabel = new JLabel("Enter Latitude");
        valTextField = new JTextField(10);        
        setBorder(BorderFactory.createTitledBorder("Latitude"));
        add(valLabel);
        add(valTextField);
    }

        public double getLatEntered()
        {
            //valTextField.setText("0");
            String input;
            double latitude;
            input = valTextField.getText();
            latitude = Double.parseDouble(input);
            return latitude;

        }
}