PDA

View Full Version : C++ with mouse click help


HawkEye
12-07-2008, 02:19 AM
ok so I want to go from text input to using click able buttons in C++. I'm leaning C++ in school and we just got past classes so you might have to dumb down answer a bit...

#include <iostream>
#include <string>

int main()
{
using namespace std;

float fine; /* total fine */
int tfine = 0; /* the total fine of ALL books */
int type1; /* this is the type of fine 1,2,3 */
int fpd, /* fines per day */ days; /* number of days */
char type2; /* the subtype a.b */

cout << "ΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓ" << endl;
cout << "\t1. General Books" << endl;
cout << "\t2. Magazines" << endl;
cout << "\t3. Refrence books" << endl;
cout << "\t4. quit" << endl;
cout << "ΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓ" << endl;
cout << endl;

do
{
cout << "please enter the code number of your book ";
cin >> type1;
}
while( type1 < 1 || type1 > 4);

while(type1 != 4)
{
switch(type1)
{
case 1:

cout << "ΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓ" << endl;
cout << "\ta. Paperbacks" << endl;
cout << "\tb. Other Genral Books" << endl;
cout << "ΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓ" << endl;
cout << endl;

do
{
cout << "please select your type of book ";
cin >> type2;
}
while( type2 < 'a' || type2 > 'b');

switch(type2)
{
case 'a': fpd = 15;
break;
case 'b': fpd = 20;
break;
}
break;

case 2: fpd = 25;
break;
case 3:
cout << "ΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓ" << endl;
cout << "\ta. Encyclopedias" << endl;
cout << "\tb. Other Reference Books" << endl;
cout << "ΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓ" << endl;
cout << endl;
do
{
cout << "please select your type of book ";
cin >> type2;
}
while( type2 < 'a' || type2 > 'b');

switch(type2)
{
case 'a': fpd = 50;
break;
case 'b': fpd = 35;
break;
}
break;
}


cout << "please enter the number of days your book was overdue ";
cin >> days;

fine = days * fpd;
cout << "your fine for this book is " << fine << endl;

cout << "ΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓ" << endl;
cout << "\t1. General Books" << endl;
cout << "\t2. Magazines" << endl;
cout << "\t3. Refrence books" << endl;
cout << "\t4. quit" << endl;
cout << "ΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓ" << endl;
cout << endl;

do
{
cout << "please enter the code number of your book ";
cin >> type1;
}
while( type1 < 1 || type1 > 4);

tfine = tfine + fine;

}


cout << "your total fine is " << tfine << endl;

return 0;
}


so I'm using Visual C++ 2008 express edition to do this and I made a windows form application and added 4 buttons to is and it looks like this

main .cpp file looks like this

#include "stdafx.h"
#include "Form1.h"

using namespace buttontest;

[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);

// Create the main window and run it
Application::Run(gcnew Form1());
return 0;
}



and form1 is


#pragma once


namespace buttontest {

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
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
/// </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::Button^ button1;
private: System::Windows::Forms::Button^ button2;
private: System::Windows::Forms::Button^ button3;
private: System::Windows::Forms::Button^ button4;
protected:

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->button1 = (gcnew System::Windows::Forms::Button());
this->button2 = (gcnew System::Windows::Forms::Button());
this->button3 = (gcnew System::Windows::Forms::Button());
this->button4 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::Point(58, 51);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(75, 23);
this->button1->TabIndex = 0;
this->button1->Text = L"General Books";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// button2
//
this->button2->Location = System::Drawing::Point(202, 51);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(75, 23);
this->button2->TabIndex = 1;
this->button2->Text = L"Magazines";
this->button2->UseVisualStyleBackColor = true;
//
// button3
//
this->button3->Location = System::Drawing::Point(58, 106);
this->button3->Name = L"button3";
this->button3->Size = System::Drawing::Size(75, 23);
this->button3->TabIndex = 2;
this->button3->Text = L"Refrence books";
this->button3->UseVisualStyleBackColor = true;
//
// button4
//
this->button4->Location = System::Drawing::Point(202, 106);
this->button4->Name = L"button4";
this->button4->Size = System::Drawing::Size(75, 23);
this->button4->TabIndex = 3;
this->button4->Text = L"quit";
this->button4->UseVisualStyleBackColor = true;
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(335, 181);
this->Controls->Add(this->button4);
this->Controls->Add(this->button3);
this->Controls->Add(this->button2);
this->Controls->Add(this->button1);
this->Name = L"Form1";
this->Text = L"Form1";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->ResumeLayout(false);

}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
}
};
}




as you can see if you read all that I want to make a button for each type of book fine. I have no clue what to do next so ya..help