Форум программистов, компьютерный форум, киберфорум
С++ для начинающих
Войти
Регистрация
Восстановить пароль
Карта форума Темы раздела Блоги Сообщество Поиск Заказать работу  
 
Рейтинг 4.67/15: Рейтинг темы: голосов - 15, средняя оценка - 4.67
0 / 2 / 0
Регистрация: 23.10.2012
Сообщений: 14
1

Калькулятор

04.11.2012, 18:34. Показов 2772. Ответов 16
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Как создать калькулятор? Самый обычный, какой есть в стандартных программах, не инженерный. С дизайном разобралась, а с кодом вообще не знаю, что делать(
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
04.11.2012, 18:34
Ответы с готовыми решениями:

Как преобразовать обычный калькулятор в калькулятор использующий класс стек?
#include <iostream> int main(){ int a = 0; int b = 0; char operation; ...

Простой калькулятор и калькулятор с парсингом
Ребят я совсем не давно только начал изучать сишку, решил написать простенький калькулятор который...

Калькулятор
Добрый вечер. Помогите пожалуйста с кодом. У меня есть код который, записывает числа в один...

Калькулятор
В методичке есть такая запись для куска кода калькулятора. TForm1 *Form1;; float...

16
Неэпический
17870 / 10635 / 2054
Регистрация: 27.09.2012
Сообщений: 26,737
Записей в блоге: 1
04.11.2012, 18:37 2
Цитата Сообщение от legalya Посмотреть сообщение
С дизайном разобралась, а с кодом вообще не знаю, что делать(
С дизайном - это в смысле на бумажке, или написали код интерфейса?
0
погромист
415 / 251 / 30
Регистрация: 27.08.2012
Сообщений: 550
04.11.2012, 19:08 3
C++
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
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
 
void info()
{
     cout << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>" << endl;
     cout <<  endl;
     cout << "+ , -, / , * , ^ " << endl;
     cout <<  endl;
     return;     
}
 
int dodavanna(int nVar1, int nVar2)
{
    int rezultat = nVar1 + nVar2;
    return rezultat;
} 
 
int vidnimanna(int nVar1, int nVar2)
{
    int rezultat = nVar1 - nVar2;
    return rezultat;
} 
 
int mnoshenna(int nVar1, int nVar2)
{
    int rezultat = nVar1 * nVar2;
    return rezultat;
}       
 
int square(int osnova, int stepin)
{
 
    int rezultat = 1;
    int i = 1;
    while (i<=stepin)
    {
          rezultat = rezultat * osnova;
          i=i+1;
          }
   
    return rezultat;
}
int main(int nNumberofArgs, char* pszArgs[])
{
    info();
 
    char diya;
    int var1;
    int var2;     
    cin >> var1;
    cin >> diya;  
    cin >> var2;
 
    switch (diya)
    {
           case '+':
                cout << dodavanna(var1, var2) << endl;
                break;
           case '-':
                cout << vidnimanna(var1, var2) << endl;
                break;
           case '*':
                cout << mnoshenna(var1, var2) << endl;
                break;
           case '^':
                cout << square(var1, var2) << endl;
                break; 
                }                              
    cout << "Press any key to continue\n";
    system("PAUSE >> void");
    return 0;
}
Простенький калькулятор
0
0 / 2 / 0
Регистрация: 23.10.2012
Сообщений: 14
04.11.2012, 19:15  [ТС] 4
я создала приложение windows forms, накидала там кнопки, сделала текстовое окно. а теперь надо сделать, чтобы оно еще и работало...
0
1 / 1 / 0
Регистрация: 01.11.2012
Сообщений: 32
04.11.2012, 19:32 5
http://rusfolder.com/33451425 ссылка работает до 2012-12-04 19:27:10
Калькуляторы из книги Культин С С++ в задачах и примерах.
0
20 / 12 / 5
Регистрация: 19.10.2012
Сообщений: 102
Записей в блоге: 1
04.11.2012, 19:51 6
В Builder можно так создать
Код
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
float a,b; AnsiString op; int f;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
f=0;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
if(f==0){
Memo1->Text=((TButton*)Sender)->Caption;
f=1;}
else
Memo1->Text=Memo1->Text+((TButton*)Sender)->Caption;
b=StrToFloat(Memo1->Text);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button12Click(TObject *Sender)
{
if(f){
a=StrToFloat(Memo1->Text);
op=((TButton*)Sender)->Caption;
Memo1->Lines->Add(((TButton*)Sender)->Caption);
f=0;}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button17Click(TObject *Sender)
{
if(op=='+'){
a+=b; f=0;}
else if(op=='-'){
a-=b;f=0;}
else if(op=='*'){
a*=b;f=0;}
else if(op=='/'){
a/=b;f=0;}
Memo1->Lines->Add(FloatToStrF(a,ffGeneral,5,2));

}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button16Click(TObject *Sender)
{
Memo1->Clear();
f=0;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button10Click(TObject *Sender)
{
if(!f){
Memo1->Text="0,";
f=1;}
else if(Memo1->Text.Pos(",")==0)
Memo1->Text=Memo1->Text+",";
}
//---------------------------------------------------------------------------
Вложения
Тип файла: rar Калькулятор.rar (370.2 Кб, 36 просмотров)
0
0 / 2 / 0
Регистрация: 23.10.2012
Сообщений: 14
04.11.2012, 19:56  [ТС] 7
Цитата Сообщение от Croessmah Посмотреть сообщение
С дизайном - это в смысле на бумажке, или написали код интерфейса?
Изначальный код у меня такой. его нужно чем-то заполнить)


C#
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
namespace WindowsFormsApplication1 {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e) {
 
        }
 
        private void button2_Click(object sender, EventArgs e) {
 
        }
 
        private void button3_Click(object sender, EventArgs e) {
 
        }
 
        private void button4_Click(object sender, EventArgs e) {
 
        }
 
        private void button5_Click(object sender, EventArgs e) {
 
        }
 
        private void button6_Click(object sender, EventArgs e) {
 
        }
 
        private void button7_Click(object sender, EventArgs e) {
 
        }
 
        private void button8_Click(object sender, EventArgs e) {
 
        }
 
        private void button9_Click(object sender, EventArgs e) {
 
        }
 
        private void button0_Click(object sender, EventArgs e) {
 
        }
 
        private void zapyatya_Click(object sender, EventArgs e) {
 
        }
 
        private void minus_Click(object sender, EventArgs e) {
 
        }
 
        private void plus_Click(object sender, EventArgs e) {
 
        }
 
        private void delenie_Click(object sender, EventArgs e) {
 
        }
 
        private void umnozhenie_Click(object sender, EventArgs e) {
 
        }
 
        private void textBox1_TextChanged(object sender, EventArgs e) {
 
        }
    }
}
0
2 / 2 / 1
Регистрация: 10.08.2012
Сообщений: 53
04.11.2012, 20:20 8
у вас просто чистый набросок windows form с кучей кнопок, но каждой кнопке нужно прописать свойство например у вас
***
private void plus_Click(object sender, EventArgs e) {
}
*****
это пустое свойство кнопки "plus" т.к между {} нечего нет.
Можно сделать так, видно что это кнопка отвечающая за сложение, так пропишем ей код сложение двух чисел:
private void plus_Click(object sender, EventArgs e)
{
int a,b,sum;
sum=a+b;
ну, а здесь нужно прописать куда будем выводить переменную sum
}
(это пример так что возможны ошибки)
0
9 / 9 / 2
Регистрация: 13.10.2012
Сообщений: 36
04.11.2012, 20:37 9
я делал консольный в своё время если нужно могу исходник скинуть
0
4 / 4 / 3
Регистрация: 28.07.2012
Сообщений: 185
04.11.2012, 20:39 10
А у меня есть на формах. И в Delphi и в C++. Если нужно, пиши в ЛС.
0
20 / 12 / 5
Регистрация: 19.10.2012
Сообщений: 102
Записей в блоге: 1
04.11.2012, 22:05 11
Первый раз на Visual Studio пробую
Код
#pragma once


namespace calculator {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;
	double a,b; int f; char op;//обьявляем переменные
	/// <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();
			f=0;
			
			//
			//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;
	protected: 
	private: System::Windows::Forms::Button^  button2;
	private: System::Windows::Forms::Button^  button3;
	private: System::Windows::Forms::Button^  button4;
	private: System::Windows::Forms::Button^  button5;
	private: System::Windows::Forms::Button^  button6;
	private: System::Windows::Forms::TextBox^  textBox1;
	private: System::Windows::Forms::Button^  button7;
	private: System::Windows::Forms::Button^  button8;
	private: System::Windows::Forms::Button^  button9;
	private: System::Windows::Forms::Button^  button10;
	private: System::Windows::Forms::Button^  button11;
	private: System::Windows::Forms::Button^  button12;
	private: System::Windows::Forms::Button^  button13;
	private: System::Windows::Forms::Button^  button14;
	private: System::Windows::Forms::Button^  button15;
	private: System::Windows::Forms::Button^  button16;
	private: System::Windows::Forms::Button^  button17;




	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->button5 = (gcnew System::Windows::Forms::Button());
			this->button6 = (gcnew System::Windows::Forms::Button());
			this->textBox1 = (gcnew System::Windows::Forms::TextBox());
			this->button7 = (gcnew System::Windows::Forms::Button());
			this->button8 = (gcnew System::Windows::Forms::Button());
			this->button9 = (gcnew System::Windows::Forms::Button());
			this->button10 = (gcnew System::Windows::Forms::Button());
			this->button11 = (gcnew System::Windows::Forms::Button());
			this->button12 = (gcnew System::Windows::Forms::Button());
			this->button13 = (gcnew System::Windows::Forms::Button());
			this->button14 = (gcnew System::Windows::Forms::Button());
			this->button15 = (gcnew System::Windows::Forms::Button());
			this->button16 = (gcnew System::Windows::Forms::Button());
			this->button17 = (gcnew System::Windows::Forms::Button());
			this->SuspendLayout();
			// 
			// button1
			// 
			this->button1->Location = System::Drawing::Point(2, 36);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(34, 34);
			this->button1->TabIndex = 0;
			this->button1->Text = L"1";
			this->button1->UseVisualStyleBackColor = true;
			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// button2
			// 
			this->button2->Location = System::Drawing::Point(42, 36);
			this->button2->Name = L"button2";
			this->button2->Size = System::Drawing::Size(35, 34);
			this->button2->TabIndex = 1;
			this->button2->Text = L"2";
			this->button2->UseVisualStyleBackColor = true;
			this->button2->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// button3
			// 
			this->button3->Location = System::Drawing::Point(83, 36);
			this->button3->Name = L"button3";
			this->button3->Size = System::Drawing::Size(35, 34);
			this->button3->TabIndex = 2;
			this->button3->Text = L"3";
			this->button3->UseVisualStyleBackColor = true;
			this->button3->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// button4
			// 
			this->button4->Location = System::Drawing::Point(2, 76);
			this->button4->Name = L"button4";
			this->button4->Size = System::Drawing::Size(35, 34);
			this->button4->TabIndex = 3;
			this->button4->Text = L"4";
			this->button4->UseVisualStyleBackColor = true;
			this->button4->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// button5
			// 
			this->button5->Location = System::Drawing::Point(42, 76);
			this->button5->Name = L"button5";
			this->button5->Size = System::Drawing::Size(35, 34);
			this->button5->TabIndex = 4;
			this->button5->Text = L"5";
			this->button5->UseVisualStyleBackColor = true;
			this->button5->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// button6
			// 
			this->button6->Location = System::Drawing::Point(83, 76);
			this->button6->Name = L"button6";
			this->button6->Size = System::Drawing::Size(35, 34);
			this->button6->TabIndex = 5;
			this->button6->Text = L"6";
			this->button6->UseVisualStyleBackColor = true;
			this->button6->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// textBox1
			// 
			this->textBox1->Location = System::Drawing::Point(2, 2);
			this->textBox1->Multiline = true;
			this->textBox1->Name = L"textBox1";
			this->textBox1->Size = System::Drawing::Size(204, 28);
			this->textBox1->TabIndex = 6;
			// 
			// button7
			// 
			this->button7->Location = System::Drawing::Point(2, 116);
			this->button7->Name = L"button7";
			this->button7->Size = System::Drawing::Size(35, 34);
			this->button7->TabIndex = 7;
			this->button7->Text = L"7";
			this->button7->UseVisualStyleBackColor = true;
			this->button7->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// button8
			// 
			this->button8->Location = System::Drawing::Point(43, 116);
			this->button8->Name = L"button8";
			this->button8->Size = System::Drawing::Size(34, 34);
			this->button8->TabIndex = 8;
			this->button8->Text = L"8";
			this->button8->UseVisualStyleBackColor = true;
			this->button8->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// button9
			// 
			this->button9->Location = System::Drawing::Point(83, 116);
			this->button9->Name = L"button9";
			this->button9->Size = System::Drawing::Size(35, 34);
			this->button9->TabIndex = 9;
			this->button9->Text = L"9";
			this->button9->UseVisualStyleBackColor = true;
			this->button9->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// button10
			// 
			this->button10->Location = System::Drawing::Point(2, 156);
			this->button10->Name = L"button10";
			this->button10->Size = System::Drawing::Size(75, 34);
			this->button10->TabIndex = 10;
			this->button10->Text = L"0";
			this->button10->UseVisualStyleBackColor = true;
			this->button10->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// button11
			// 
			this->button11->Location = System::Drawing::Point(83, 156);
			this->button11->Name = L"button11";
			this->button11->Size = System::Drawing::Size(35, 34);
			this->button11->TabIndex = 11;
			this->button11->Text = L",";
			this->button11->UseVisualStyleBackColor = true;
			this->button11->Click += gcnew System::EventHandler(this, &Form1::button11_Click);
			// 
			// button12
			// 
			this->button12->Location = System::Drawing::Point(124, 36);
			this->button12->Name = L"button12";
			this->button12->Size = System::Drawing::Size(38, 34);
			this->button12->TabIndex = 12;
			this->button12->Text = L"+";
			this->button12->UseVisualStyleBackColor = true;
			this->button12->Click += gcnew System::EventHandler(this, &Form1::button12_Click);
			// 
			// button13
			// 
			this->button13->Location = System::Drawing::Point(124, 76);
			this->button13->Name = L"button13";
			this->button13->Size = System::Drawing::Size(38, 34);
			this->button13->TabIndex = 13;
			this->button13->Text = L"-";
			this->button13->UseVisualStyleBackColor = true;
			this->button13->Click += gcnew System::EventHandler(this, &Form1::button13_Click);
			// 
			// button14
			// 
			this->button14->Location = System::Drawing::Point(124, 116);
			this->button14->Name = L"button14";
			this->button14->Size = System::Drawing::Size(38, 34);
			this->button14->TabIndex = 14;
			this->button14->Text = L"*";
			this->button14->UseVisualStyleBackColor = true;
			this->button14->Click += gcnew System::EventHandler(this, &Form1::button14_Click);
			// 
			// button15
			// 
			this->button15->Location = System::Drawing::Point(124, 156);
			this->button15->Name = L"button15";
			this->button15->Size = System::Drawing::Size(38, 34);
			this->button15->TabIndex = 15;
			this->button15->Text = L"/";
			this->button15->UseVisualStyleBackColor = true;
			this->button15->Click += gcnew System::EventHandler(this, &Form1::button15_Click);
			// 
			// button16
			// 
			this->button16->Location = System::Drawing::Point(168, 36);
			this->button16->Name = L"button16";
			this->button16->Size = System::Drawing::Size(38, 74);
			this->button16->TabIndex = 16;
			this->button16->Text = L"C";
			this->button16->UseVisualStyleBackColor = true;
			this->button16->Click += gcnew System::EventHandler(this, &Form1::button16_Click);
			// 
			// button17
			// 
			this->button17->Location = System::Drawing::Point(168, 116);
			this->button17->Name = L"button17";
			this->button17->Size = System::Drawing::Size(38, 74);
			this->button17->TabIndex = 17;
			this->button17->Text = L"=";
			this->button17->UseVisualStyleBackColor = true;
			this->button17->Click += gcnew System::EventHandler(this, &Form1::button17_Click);
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(212, 195);
			this->Controls->Add(this->button17);
			this->Controls->Add(this->button16);
			this->Controls->Add(this->button15);
			this->Controls->Add(this->button14);
			this->Controls->Add(this->button13);
			this->Controls->Add(this->button12);
			this->Controls->Add(this->button11);
			this->Controls->Add(this->button10);
			this->Controls->Add(this->button9);
			this->Controls->Add(this->button8);
			this->Controls->Add(this->button7);
			this->Controls->Add(this->textBox1);
			this->Controls->Add(this->button6);
			this->Controls->Add(this->button5);
			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->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
				 if(f==0){
					 textBox1->Text=((Button^)sender)->Text;
					 f=1;}
				 else
					 textBox1->Text+=((Button^)sender)->Text;
				 b=Convert::ToDouble(textBox1->Text);
			 }


private: System::Void button12_Click(System::Object^  sender, System::EventArgs^  e) {
			 if(f){
			 a=Convert::ToDouble(textBox1->Text);
			 op='+';
			 textBox1->Text="+";
			 f=0;}

		 }
private: System::Void button13_Click(System::Object^  sender, System::EventArgs^  e) {
			 if(f){
			 a=Convert::ToDouble(textBox1->Text);
			 op='-';
			 textBox1->Text="-";
			 f=0;}
		 }
private: System::Void button14_Click(System::Object^  sender, System::EventArgs^  e) {
			 if(f){
				 a=Convert::ToDouble(textBox1->Text);
				 op='*';
				 textBox1->Text="*";
				 f=0;}
		 }
private: System::Void button15_Click(System::Object^  sender, System::EventArgs^  e) {
			 if(f){
				 a=Convert::ToDouble(textBox1->Text);
				 op='/';
				 textBox1->Text="/";
				 f=0;}
		 }
private: System::Void button17_Click(System::Object^  sender, System::EventArgs^  e) {
			 switch(op){
				 case '+':
					 a+=b;
					 break;
				 case '-':
					 a-=b;
					 break;
				 case '*':
					 a*=b;
					 break;
				 case '/':
					 a/=b;
					 break;}
			 textBox1->Text=Convert::ToString(a);
		 }
private: System::Void button16_Click(System::Object^  sender, System::EventArgs^  e) {
			 textBox1->Clear();
			 f=0;
		 }
private: System::Void button11_Click(System::Object^  sender, System::EventArgs^  e) {
			 if(!f){
				 textBox1->Text="0,";
				 f=1;}
			 else
				 textBox1->Text=textBox1->Text+",";


		 }
};
}
Вложения
Тип файла: rar calculator.rar (2.82 Мб, 14 просмотров)
0
0 / 2 / 0
Регистрация: 23.10.2012
Сообщений: 14
05.11.2012, 12:57  [ТС] 12
Цитата Сообщение от NewProject Посмотреть сообщение
у вас просто чистый набросок windows form с кучей кнопок, но каждой кнопке нужно прописать свойство например у вас
***
private void plus_Click(object sender, EventArgs e) {
}
*****
это пустое свойство кнопки "plus" т.к между {} нечего нет.
Можно сделать так, видно что это кнопка отвечающая за сложение, так пропишем ей код сложение двух чисел:
private void plus_Click(object sender, EventArgs e)
{
int a,b,sum;
sum=a+b;
ну, а здесь нужно прописать куда будем выводить переменную sum
}
(это пример так что возможны ошибки)

там есть еще проблемы с кнопкой равно. что с ней делать?

Добавлено через 57 секунд
и как сделать, чтобы он понял, что это за а и б?

Добавлено через 9 минут
нужно) сейчас напишу)

Добавлено через 6 минут
Цитата Сообщение от qmen Посмотреть сообщение
я делал консольный в своё время если нужно могу исходник скинуть
скидывай. интересно посмотреть.
0
9 / 9 / 2
Регистрация: 13.10.2012
Сообщений: 36
05.11.2012, 14:37 13
Цитата Сообщение от legalya Посмотреть сообщение
скидывай. интересно посмотреть.
Но сразу предупреждаю что делал я его ещё на первом курсе поэтому код скорее всего немного корявый
C++
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "stdio.h"
#include "math.h"
#include <locale.h>
#include "windows.h"
int main()
{
int a,b,c,d,g,i,o,w,f1,f2,o1,o2,u2,u1,m21,m22,t ,u;
float q,p,y,v,l,x,e1,e2,l1,l2;
u1=1;
u2=2;
setlocale(LC_CTYPE, ".1251");
printf("Для целых чисел нажмите 1,для дробных 2: ");
scanf("%d",&a);
if(a==1)
{
while(u=1)
 
{
printf("\n%s\n%s","Нажмите 1 для сложения,2 для вычитания,3 для умножения,","4 для деления,для вычитания квадратных корней нажмите 5: ");
scanf("%d",&b);
if(b==1)
{
printf("Введите 1-ое число: ");
scanf("%d",&c);
printf("Введите 2-ое число: ");
scanf("%d",&d);
printf("%s%d","Результат: ",c+d);
}
if(b==2)
{
printf("Введите 1-ое число: ");
scanf("%d",&g);
printf("Введите 2-ое число: ");
scanf(" %d",&i);
printf("%s%d","Результат: ",g-i);
}
if(b==3)
{
printf("Введите 1-ое число: ");
scanf("%d",&o);
printf("Введите 2-ое число: ");
scanf(" %d",&w);
printf("%s%d","Результат: ",w*o);
}
if(b==4)
{
printf("Введите 1-ое число: ");
scanf("%d",&f1);
printf("Введите 2-ое число: ");
scanf(" %d",&f2);
printf("%s%d","Ваш результат: ",f1/f2);
}
if(b==5)
{
printf("Введите число для извлечения квадратного корня ");
scanf("%d",&o1);
int o2 =(int) sqrt(o1);
printf("%s%d","Корень: ",o2);
}
printf("\n%s","Чтобы посчитать ещё раз нажмите 1,чтобы выйти нажмите 2: ");
scanf("%d",&m21);
Sleep (1500);
if(m21==2) return 0;
}
 
}
if(a==2)
{
while(u2=2)
 
{
printf("\n%s\n%s","Нажмите 1 для сложения,2 для вычитания,3 для умножения,","4 для деления,для вычитания квадратных корней нажмите 5: ");
scanf("%d",&t);
if(t==1)
{
 printf("Введите 1-ое число:");
 scanf("%f",&q);
 printf("Введите 2-ое число:") ;
 scanf("%f",&p);
printf("%s%f","Ваш результат: ",q+p);
 
}
 
if(t==2)
 {
printf("Enter 1 number ");
 scanf("%f",&y);
 printf("Enter 2 number ") ;
 scanf("%f",&v);
printf("%s%f","Ваш результат ",y-v);
 
 }
if(t==3)
 {
printf("Enter 1 number ");
 scanf("%f",&l);
 printf("Enter 2 number ") ;
 scanf("%f",&x);
printf("%s%f","Ваш результат ",l*x);
 
}
if(t==4)
 {
printf("Введите 1-ое число  ");
 scanf("%f",&e1);
 printf("Введите 2-ое число") ;
 scanf("%f",&e2);
printf("%s%f","Ваш результат: ",e1/e2);
 
}
 if(t==5)
 {
printf("Введите число для извлечения корня: ");
scanf("%f",&l1);
float l2 =(float) sqrt(l1);
printf("%s%f","Ваш корень: ",l2);
 
 }
    printf("\n%s","Посчитать ещё раз?1-да,2-нет ");
  scanf("%d",&m22);
  Sleep(5000);
  if(m22==2) return 0;
 
  }
 
}
return 0;
}
0
0 / 2 / 0
Регистрация: 23.10.2012
Сообщений: 14
05.11.2012, 20:03  [ТС] 14
спасибо

Добавлено через 3 минуты
Цитата Сообщение от lordik55 Посмотреть сообщение
А у меня есть на формах. И в Delphi и в C++. Если нужно, пиши в ЛС.
если честно, я тут совсем недавно и не разобралась, как писать в лс. или мне пока недоступна эта функция?

Добавлено через 1 час 2 минуты
Цитата Сообщение от qmen Посмотреть сообщение
Но сразу предупреждаю что делал я его ещё на первом курсе поэтому код скорее всего немного корявый
C++
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "stdio.h"
#include "math.h"
#include <locale.h>
#include "windows.h"
int main()
{
int a,b,c,d,g,i,o,w,f1,f2,o1,o2,u2,u1,m21,m22,t ,u;
float q,p,y,v,l,x,e1,e2,l1,l2;
u1=1;
u2=2;
setlocale(LC_CTYPE, ".1251");
printf("Для целых чисел нажмите 1,для дробных 2: ");
scanf("%d",&a);
if(a==1)
{
while(u=1)
 
{
printf("\n%s\n%s","Нажмите 1 для сложения,2 для вычитания,3 для умножения,","4 для деления,для вычитания квадратных корней нажмите 5: ");
scanf("%d",&b);
if(b==1)
{
printf("Введите 1-ое число: ");
scanf("%d",&c);
printf("Введите 2-ое число: ");
scanf("%d",&d);
printf("%s%d","Результат: ",c+d);
}
if(b==2)
{
printf("Введите 1-ое число: ");
scanf("%d",&g);
printf("Введите 2-ое число: ");
scanf(" %d",&i);
printf("%s%d","Результат: ",g-i);
}
if(b==3)
{
printf("Введите 1-ое число: ");
scanf("%d",&o);
printf("Введите 2-ое число: ");
scanf(" %d",&w);
printf("%s%d","Результат: ",w*o);
}
if(b==4)
{
printf("Введите 1-ое число: ");
scanf("%d",&f1);
printf("Введите 2-ое число: ");
scanf(" %d",&f2);
printf("%s%d","Ваш результат: ",f1/f2);
}
if(b==5)
{
printf("Введите число для извлечения квадратного корня ");
scanf("%d",&o1);
int o2 =(int) sqrt(o1);
printf("%s%d","Корень: ",o2);
}
printf("\n%s","Чтобы посчитать ещё раз нажмите 1,чтобы выйти нажмите 2: ");
scanf("%d",&m21);
Sleep (1500);
if(m21==2) return 0;
}
 
}
if(a==2)
{
while(u2=2)
 
{
printf("\n%s\n%s","Нажмите 1 для сложения,2 для вычитания,3 для умножения,","4 для деления,для вычитания квадратных корней нажмите 5: ");
scanf("%d",&t);
if(t==1)
{
 printf("Введите 1-ое число:");
 scanf("%f",&q);
 printf("Введите 2-ое число:") ;
 scanf("%f",&p);
printf("%s%f","Ваш результат: ",q+p);
 
}
 
if(t==2)
 {
printf("Enter 1 number ");
 scanf("%f",&y);
 printf("Enter 2 number ") ;
 scanf("%f",&v);
printf("%s%f","Ваш результат ",y-v);
 
 }
if(t==3)
 {
printf("Enter 1 number ");
 scanf("%f",&l);
 printf("Enter 2 number ") ;
 scanf("%f",&x);
printf("%s%f","Ваш результат ",l*x);
 
}
if(t==4)
 {
printf("Введите 1-ое число  ");
 scanf("%f",&e1);
 printf("Введите 2-ое число") ;
 scanf("%f",&e2);
printf("%s%f","Ваш результат: ",e1/e2);
 
}
 if(t==5)
 {
printf("Введите число для извлечения корня: ");
scanf("%f",&l1);
float l2 =(float) sqrt(l1);
printf("%s%f","Ваш корень: ",l2);
 
 }
    printf("\n%s","Посчитать ещё раз?1-да,2-нет ");
  scanf("%d",&m22);
  Sleep(5000);
  if(m22==2) return 0;
 
  }
 
}
return 0;
}

мне он почему-то показываеи, что там уйма ошибок. это точно консольное приложение? и точно С++?

Добавлено через 2 минуты
все, я поняла, в чем проблема.
0
9 / 9 / 2
Регистрация: 13.10.2012
Сообщений: 36
05.11.2012, 20:25 15
Цитата Сообщение от legalya Посмотреть сообщение
все, я поняла, в чем проблема
сейчас работает?
0
0 / 2 / 0
Регистрация: 23.10.2012
Сообщений: 14
05.11.2012, 20:27  [ТС] 16
да, спасибо)
0
2 / 2 / 1
Регистрация: 10.08.2012
Сообщений: 53
05.11.2012, 22:31 17
Цитата Сообщение от legalya Посмотреть сообщение
там есть еще проблемы с кнопкой равно. что с ней делать?

Добавлено через 57 секунд
и как сделать, чтобы он понял, что это за а и б?

Добавлено через 9 минут
нужно) сейчас напишу)

Добавлено через 6 минут


скидывай. интересно посмотреть.
вот пример я тоже раньше этим занимался
C++ (Qt)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
             int a =Convert::ToInt32(this->textbox1->Text);
              int b =Convert::ToInt32(this->textbox2->Text);
 
              if  (radioButton1->Checked)
              {      
            int s=a+b;
            label2->Text = System::Convert::ToString(s);        
              }
             
    else  if     (radioButton2->Checked)
              {
            int s=a-b;
            label2->Text = System::Convert::ToString(s);
              }
             else  if    (radioButton3->Checked)
              {
            int s=a*b;
            label2->Text = System::Convert::ToString(s);
              }else  if  (radioButton4->Checked)
              {
            int s=a/b;
            label2->Text = System::Convert::ToString(s);
              }
написано на VS 2010 это часть кода моего калькулятора на форме имеются несколько радиобатанов
и в зависимости какой из них выбран выполняется действие к примеру здесь
C++ (Qt)
1
2
3
4
 if  (radioButton3->Checked)
              {
            int s=a*b;
            label2->Text = System::Convert::ToString(s);
выбран 3 радиобатан и выполняется действие умножения целых чисел int s=a*b; дальше выводим значение на label ну а переменные a и b берем из текст боксов вот и весь калькулятор
0
05.11.2012, 22:31
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
05.11.2012, 22:31
Помогаю со студенческими работами здесь

Калькулятор
Помогите сделать калькулятор. По запросу с клавиатуры в консольном приложении вводится строка,...

Калькулятор
#include &quot;stdafx.h&quot; #include &quot;iostream&quot; using namespace std; int main() { double sot;...

Калькулятор
супер-простой калькулятор: Здравствуйте, помогите сделать задание. Введите число: 10 (может...

Калькулятор на C++
Доброго времени суток! У меня возник вопрос. При вводе чисел в cmd, они у меня просто складываются,...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
17
Ответ Создать тему
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru