سلام دوستان .
کد برنامه ماشین حساب به c ++ را میخواستم . که علاوه بر 4 عمل اصلی بتونه tan , cot , sin , cos و درصد را حساب کنه .
و بتونه جمع متوالی و ضرب و ... را بصورت متوالی انجام بده .
شرمنده میکنید کمک کنید.
سپاسگذار شما freemind
Printable View
سلام دوستان .
کد برنامه ماشین حساب به c ++ را میخواستم . که علاوه بر 4 عمل اصلی بتونه tan , cot , sin , cos و درصد را حساب کنه .
و بتونه جمع متوالی و ضرب و ... را بصورت متوالی انجام بده .
شرمنده میکنید کمک کنید.
سپاسگذار شما freemind
اگه پروژه دانشجویی نمیخوای قرار بدم؟...
در غیر این صورت خودت باید بنویسی.
قطعا پروژه دانش آموزی یا دانشجویی هست وگرنه نیازی به خواستن کد نبود و یک راهنمایی کافی بود...
دوستان من ترم 4 هستم دانشکده امام محمد باقر ساری . c را پاس کردم و در قسمت وی بی همین سایت آموزش ویروس نویسی میدادم و از روزی که وارد این سایت شدم دانشگا ه هم میرفتم . پس پروژه نیست . اگه بود باید 1 سال پیش درخواست میدادم . واینکه خود این برنامه را ویبی بطور کامل یعنی همون ماشین حساب کامپیوتر را درست کردم ولی از خود c خوب سر در نمیارم . و سوم اینکه اگه هم پروژه بود الآن چرا ؟ 10 تیر امتحانات تموم شد و نمرات ما همه اومده . قبول ندارین برین سایتمن این برنامه را میخوام نه به عنوان پروژه . اگه کسی تونست کد را بده که ممنون . در غیر اینصورت دم همه شما گرم .کد:www.saritc.ir
یا علی
سلام.
مساله پروژه بودن یا نبودنش نیست. مساله اینه که درخواست سورس آماده خلاف قوانین سایت هست.
گذشته از این حرفا ماشین حساب که خیلی سادست. 1 سرچ بکنی تا دلت بخواد پیدا میکنی.
شما سورس ويبي بدين ما به C تبديل کنيم .نقل قول:
این سورس ویبی
کد:Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Private Type NOTIFYICONDATA
cbSize As Long
hWnd As Long
uId As Long
uFlags As Long
ucallbackMessage As Long
hIcon As Long
szTip As String * 64
End Type
Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
Private Const WM_LBUTTONDBLCLK = &H203
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_RBUTTONUP = &H205
Dim tNID As NOTIFYICONDATA
Dim af, bf, cf, df, ef, md, not1, lch1, lm, ln, xy, p, sinf, mmosbat As Double
Dim i As Integer
Dim m As Integer
Dim ctrl As Byte
Dim ctrls As String
Dim clpboard As String
Private Sub Command10_Click()
List1.RemoveItem Val(List1.ListCount - 1)
End Sub
Private Sub AboutCalculator_Click()
Form4.Show
Form1.Hide
End Sub
Private Sub and_Click()
msg = MsgBox("åäæÒ ˜Ïí ÈÑÇí Çíä Ϙãå äæÔÊå äÔÏå ÇÓÊ !", vbExclamation, "ÎØÇ")
End Sub
Private Sub bin_opt_Click()
If bin_opt.Value = True Then
tow.Enabled = False
Command3.Enabled = False
Command4.Enabled = False
Command5.Enabled = False
Command6.Enabled = False
Command7.Enabled = False
Command8.Enabled = False
Command9.Enabled = False
a.Enabled = False
b.Enabled = False
c.Enabled = False
d.Enabled = False
e.Enabled = False
f.Enabled = False
Command33.Enabled = False
End If
End Sub
Private Sub binary_Click()
hexmnu.Checked = False
octal.Checked = False
binary.Checked = True
Decimalmnu.Checked = False
End Sub
Private Sub bkspc_Click()
On Error GoTo errlabel
errlabel:
If Err.Number = 5 Then
msg = MsgBox("not was number for delete", vbCritical, "error")
txtshow.Text = Val("0")
End If
txtshow.Text = Left(txtshow.Text, Len(txtshow.Text) - 1)
End Sub
Private Sub c1_Click()
Call defaults
End Sub
Private Sub c2_Click()
txtshow.Text = Clear
txtshow = Val("0") & "."
End Sub
Private Sub Command2_Click()
End Sub
Private Sub Command1_Click()
End Sub
Private Sub Command14_Click()
Select Case ctrl
Case 1
txtshow.Text = m + Val(txtshow.Text)
m = Clear
Case 2
If Len(txtshow.Text) <= 0 Then
Else
List1.AddItem Val(txtshow.Text)
End If
mn = List1.List(0)
For lm = 1 To List1.ListCount - 1
''Print List1.List(lm)
If Val(List1.List(lm)) < 0 Then
mn = mn + Val((-List1.List(lm)))
Else
mn = mn - List1.List(lm)
End If
txtshow.Text = mn
Next lm
mn = Clear
lm = Clear
List1.Clear
Case 3
If Len(txtshow.Text) <= 0 Then
Else
List2.AddItem Val(txtshow.Text)
End If
mn = List2.List(0)
For lm = 1 To List2.ListCount - 1
''Print List2.List(lm)
If Val(List2.List(lm)) < 0 Then
mn = mn * Val((-List2.List(lm)))
Else
mn = mn * List2.List(lm)
End If
txtshow.Text = mn
Next lm
mn = Clear
lm = Clear
List2.Clear
Case 4
If Len(txtshow.Text) <= 0 Then
Else
List3.AddItem Val(txtshow.Text)
End If
mn = List3.List(0)
For lm = 1 To List3.ListCount - 1
''Print List3.List(lm)
If Val(List3.List(lm)) < 0 Then
mn = mn / Val((-List3.List(lm)))
Else
mn = mn / List3.List(lm)
End If
txtshow.Text = mn
Next lm
mn = Clear
lm = Clear
List3.Clear
Case 5
On Error GoTo fazierror1
fazierror1:
If Err.Number = 11 Then
msg = MsgBox("noe was number for mod", vbCritical, "err")
txtshow.Text = 777
End If
m = md Mod Val(txtshow.Text)
txtshow.Text = m
m = Clear
Case 7
For i = 1 To Val(txtshow.Text)
lch1 = lch1 * 2
Next i
txtshow.Text = lch1
End Select
If Len(txtshow.Text) <= 0 Then
msg = MsgBox("no mutch found", vbCritical, "error")
List3.AddItem txtshow.Text
List3.RemoveItem List3.ListCount - 1
Else
List3.AddItem txtshow.Text
txtshow.Text = Clear
End If
ctrl = 4
End Sub
Private Sub Command17_Click()
msg = MsgBox("åäæÒ ˜Ïí ÈÑÇí Çíä Ϙãå äæÔÊå äÔÏå ÇÓÊ !", vbExclamation, "ÎØÇ")
End Sub
Private Sub Command18_Click()
msg = MsgBox("åäæÒ ˜Ïí ÈÑÇí Çíä Ϙãå äæÔÊå äÔÏå ÇÓÊ !", vbExclamation, "ÎØÇ")
End Sub
Private Sub Command19_Click()
Select Case ctrl
Case 1
txtshow.Text = m + Val(txtshow.Text)
m = Clear
Case 2
If Len(txtshow.Text) <= 0 Then
Else
List1.AddItem Val(txtshow.Text)
End If
mn = List1.List(0)
For lm = 1 To List1.ListCount - 1
''Print List1.List(lm)
If Val(List1.List(lm)) < 0 Then
mn = mn + Val((-List1.List(lm)))
Else
mn = mn - List1.List(lm)
End If
txtshow.Text = mn
Next lm
mn = Clear
lm = Clear
List1.Clear
Case 3
If Len(txtshow.Text) <= 0 Then
Else
List2.AddItem Val(txtshow.Text)
End If
mn = List2.List(0)
For lm = 1 To List2.ListCount - 1
''Print List2.List(lm)
If Val(List2.List(lm)) < 0 Then
mn = -mn * Val((-List2.List(lm)))
Else
mn = mn * List2.List(lm)
End If
txtshow.Text = mn
Next lm
mn = Clear
lm = Clear
List2.Clear
Case 4
If Len(txtshow.Text) <= 0 Then
Else
List3.AddItem Val(txtshow.Text)
End If
mn = List3.List(0)
For lm = 1 To List3.ListCount - 1
''Print List3.List(lm)
If Val(List3.List(lm)) < 0 Then
mn = mn / Val((-List3.List(lm)))
Else
mn = mn / List3.List(lm)
End If
txtshow.Text = mn
Next lm
mn = Clear
lm = Clear
List3.Clear
Case 5
On Error GoTo fazierror1
fazierror1:
If Err.Number = 11 Then
msg = MsgBox("noe was number for mod", vbCritical, "err")
txtshow.Text = 777
End If
m = md Mod Val(txtshow.Text)
txtshow.Text = m
m = Clear
Case 7
For i = 1 To Val(txtshow.Text)
lch1 = lch1 * 2
Next i
txtshow.Text = lch1
End Select
If Len(txtshow.Text) <= 0 Then
msg = MsgBox("no mutch found", vbCritical, "error")
List2.AddItem txtshow.Text
List2.RemoveItem List2.ListCount - 1
Else
List2.AddItem txtshow.Text
txtshow.Text = Clear
End If
ctrl = 3
End Sub
Private Sub Command20_Click()
Select Case ctrl
Case 1
txtshow.Text = m + Val(txtshow.Text)
m = Clear
Case 2
If Len(txtshow.Text) <= 0 Then
Else
List1.AddItem Val(txtshow.Text)
End If
mn = List1.List(0)
For lm = 1 To List1.ListCount - 1
''Print List1.List(lm)
If Val(List1.List(lm)) < 0 Then
mn = mn + Val((-List1.List(lm)))
Else
mn = mn - List1.List(lm)
End If
txtshow.Text = mn
Next lm
mn = Clear
lm = Clear
List1.Clear
Case 3
If Len(txtshow.Text) <= 0 Then
Else
List2.AddItem Val(txtshow.Text)
End If
mn = List2.List(0)
For lm = 1 To List2.ListCount - 1
''Print List2.List(lm)
If Val(List2.List(lm)) < 0 Then
mn = mn * Val((-List2.List(lm)))
Else
mn = mn * List2.List(lm)
End If
txtshow.Text = mn
Next lm
mn = Clear
lm = Clear
List2.Clear
Case 4
If Len(txtshow.Text) <= 0 Then
Else
List3.AddItem Val(txtshow.Text)
End If
mn = List3.List(0)
For lm = 1 To List3.ListCount - 1
''Print List3.List(lm)
If Val(List3.List(lm)) < 0 Then
mn = mn / Val((-List3.List(lm)))
Else
mn = mn / List3.List(lm)
End If
txtshow.Text = mn
Next lm
mn = Clear
lm = Clear
List3.Clear
Case 5
On Error GoTo fazierror1
fazierror1:
If Err.Number = 11 Then
msg = MsgBox("noe was number for mod", vbCritical, "err")
txtshow.Text = 777
End If
m = md Mod Val(txtshow.Text)
txtshow.Text = m
m = Clear
Case 7
For i = 1 To Val(txtshow.Text)
lch1 = lch1 * 2
Next i
txtshow.Text = lch1
End Select
af = Val(txtshow.Text)
m = m + af
txtshow = Clear
ctrl = 1
End Sub
Private Sub Command21_Click()
Select Case ctrl
Case 1
txtshow.Text = m + Val(txtshow.Text)
m = Clear
Case 2
If Len(txtshow.Text) <= 0 Then
Else
List1.AddItem Val(txtshow.Text)
End If
mn = List1.List(0)
For lm = 1 To List1.ListCount - 1
''Print List1.List(lm)
If Val(List1.List(lm)) < 0 Then
mn = mn + Val((-List1.List(lm)))
Else
mn = mn - List1.List(lm)
End If
txtshow.Text = mn
Next lm
mn = Clear
lm = Clear
List1.Clear
Case 3
If Len(txtshow.Text) <= 0 Then
Else
List2.AddItem Val(txtshow.Text)
End If
mn = List2.List(0)
For lm = 1 To List2.ListCount - 1
''Print List2.List(lm)
If Val(List2.List(lm)) < 0 Then
mn = mn * Val((-List2.List(lm)))
Else
mn = mn * List2.List(lm)
End If
txtshow.Text = mn
Next lm
mn = Clear
lm = Clear
List2.Clear
Case 4
If Len(txtshow.Text) <= 0 Then
Else
List3.AddItem Val(txtshow.Text)
End If
mn = List3.List(0)
For lm = 1 To List3.ListCount - 1
''Print List3.List(lm)
If Val(List3.List(lm)) < 0 Then
mn = mn / Val((-List3.List(lm)))
Else
mn = mn / List3.List(lm)
End If
txtshow.Text = mn
Next lm
mn = Clear
lm = Clear
List3.Clear
Case 5
On Error GoTo fazierror1
fazierror1:
If Err.Number = 11 Then
msg = MsgBox("noe was number for mod", vbCritical, "err")
txtshow.Text = 777
End If
m = md Mod Val(txtshow.Text)
txtshow.Text = m
m = Clear
Case 7
For i = 1 To Val(txtshow.Text)
lch1 = lch1 * 2
Next i
txtshow.Text = lch1
End Select
If Len(txtshow.Text) <= 0 Then
msg = MsgBox("no mutch found", vbCritical, "error")
List1.AddItem txtshow.Text
List1.RemoveItem List1.ListCount - 1
Else
List1.AddItem txtshow.Text
txtshow.Text = Clear
End If
ctrl = 2
End Sub
Private Sub Command22_Click()
Select Case ctrl
Case 1
txtshow.Text = m + Val(txtshow.Text)
m = Clear
Case 2
If Len(txtshow.Text) <= 0 Then
Else
List1.AddItem Val(txtshow.Text)
End If
mn = List1.List(0)
For lm = 1 To List1.ListCount - 1
''Print List1.List(lm)
If Val(List1.List(lm)) < 0 Then
mn = mn + Val((-List1.List(lm)))
Else
mn = mn - List1.List(lm)
End If
txtshow.Text = mn
Next lm
mn = Clear
lm = Clear
List1.Clear
Case 3
If Len(txtshow.Text) <= 0 Then
Else
List2.AddItem Val(txtshow.Text)
End If
mn = List2.List(0)
For lm = 1 To List2.ListCount - 1
''Print List2.List(lm)
If Val(List2.List(lm)) < 0 Then
mn = -mn * Val((-List2.List(lm)))
Else
mn = mn * List2.List(lm)
End If
txtshow.Text = mn
Next lm
mn = Clear
lm = Clear
List2.Clear
Case 4
If Len(txtshow.Text) <= 0 Then
Else
List3.AddItem Val(txtshow.Text)
End If
mn = List3.List(0)
For lm = 1 To List3.ListCount - 1
''Print List3.List(lm)
If Val(List3.List(lm)) < 0 Then
mn = -mn / Val((-List3.List(lm)))
Else
mn = mn / List3.List(lm)
End If
txtshow.Text = mn
Next lm
mn = Clear
lm = Clear
List3.Clear
Case 5
On Error GoTo fazierror1
fazierror1:
If Err.Number = 11 Then
msg = MsgBox("noe was number for mod", vbCritical, "err")
txtshow.Text = 777
End If
m = md Mod Val(txtshow.Text)
txtshow.Text = m
m = Clear
Case 7
If txtshow.Text = "" Then
For i = 1 To lch1
lch1 = lch1 * 2
Next i
txtshow.Text = lch1
Else
For i = 1 To Val(txtshow.Text)
lch1 = lch1 * 2
Next i
txtshow.Text = lch1
End If
Case 6
txtshow.Text = xy ^ txtshow.Text
End Select
ctrl = 8
End Sub
Private Sub Command23_Click()
lch1 = Val(txtshow.Text)
txtshow.Text = Clear
ctrl = 7
End Sub
Private Sub Command3_Click()
If Val(txtshow.Text) = 0 Then
txtshow = Clear
End If
txtshow = txtshow & Val("3")
End Sub
Private Sub Command32_Click()
txtshow.Text = "-" & Val(txtshow.Text)
End Sub
Private Sub Command33_Click()
txtshow.Text = txtshow + "."
End Sub
Private Sub Command36_Click()
If Len(txtshow.Text) <= 0 Then
txtshow.Text = "cannot divide by zero."
Else
txtshow.Text = 1 / Val(txtshow.Text)
End If
End Sub
Private Sub Command37_Click()
End Sub
Private Sub Command39_Click()
ctrl = 11
End Sub
Private Sub Command4_Click()
If Val(txtshow.Text) = 0 Then
txtshow = Clear
End If
txtshow = txtshow & Val("4")
End Sub
Private Sub Command41_Click()
xy = Val(txtshow.Text)
txtshow.Text = Clear
ctrl = 6
End Sub
Private Sub Command42_Click()
xy = Val(txtshow.Text)
txtshow.Text = xy ^ 3
End Sub
Private Sub Command5_Click()
If Val(txtshow.Text) = 0 Then
txtshow = Clear
End If
txtshow = txtshow & Val("5")
End Sub
Private Sub Command52_Click()
End Sub
Private Sub Command6_Click()
If Val(txtshow.Text) = 0 Then
txtshow = Clear
End If
txtshow = txtshow & Val("6")
End Sub
Private Sub Command7_Click()
If Val(txtshow.Text) = 0 Then
txtshow = Clear
End If
txtshow = txtshow & Val("7")
End Sub
Private Sub Command8_Click()
If Val(txtshow.Text) = 0 Then
txtshow = Clear
End If
txtshow = txtshow & Val("8")
End Sub
Private Sub Command9_Click()
If Val(txtshow.Text) = 0 Then
txtshow = Clear
End If
txtshow = txtshow & Val("9")
End Sub
Private Sub copy_Click()
clpboard = txtshow.Text
paste.Enabled = True
End Sub
Private Sub Decimal_Click()
End Sub
Private Sub cos_Click()
End Sub
Private Sub cos_cmd_Click()
If hpy_chk Then
txtshow.Text = ((2.7181 ^ Val(txtshow.Text)) + (2.7181 ^ Val(-txtshow.Text))) / 2
Else
p = 4 * Atn(1)
sinf = Val(txtshow.Text) / 180 * p
txtshow.Text = Cos(sinf)
End If
hyp_chk.Value = False
End Sub
Private Sub dec_opt_Click()
tow.Enabled = True
Command3.Enabled = True
Command4.Enabled = True
Command5.Enabled = True
Command6.Enabled = True
Command7.Enabled = True
Command8.Enabled = True
Command9.Enabled = True
a.Enabled = False
b.Enabled = False
c.Enabled = False
d.Enabled = False
e.Enabled = False
f.Enabled = False
Command33.Enabled = True
End Sub
Private Sub Decimalmnu_Click()
hexmnu.Checked = False
octal.Checked = False
binary.Checked = False
Decimalmnu.Checked = True
End Sub
Private Sub degreesmenu_Click()
degreesmenu.Checked = True
radiansmnu.Checked = False
gradsmnu.Checked = False
End Sub
Private Sub exp_cmd_Click()
txtshow.Text = Exp(txtshow.Text)
End Sub
Private Sub fact_cmd_Click()
On Error GoTo errlabel
Dim X As Integer
X = txtshow.Text
If X < 0 Then
msg = MsgBox("eroor ! number--> >= 0", vbOKOnly + vbExclamation, "error")
Call defaults
Exit Sub
Else
txtshow.Text = fact(txtshow.Text)
End If
errlabel:
If Err.Number = 6 Then
msg = MsgBox("number is over flow ", vbOKOnly + vbCritical, "error")
Call defaults
Exit Sub
End If
End Sub
Private Function fact(X As Integer) As Double
If X = 0 Then
fact = 1
Else
fact = fact(X - 1) * X
End If
End Function
Private Sub Form_Load()
'' i = GetSetting("af", "af soft", "PassCheck", "0")
''If i >= 7 Then
'' MsgBox "ÔãÇ Ïíå äãí ÊæäíÏ ÇÒ Çíä ÈÑäÇãå ÇÓÊÝÇÏå ˜äíÏ", , "ÇíÇä ãåáÊ"
''End
''End If
'' SaveSetting "af", "af soft", "PassCheck", Val(i) + 1
'' MsgBox "ÔãÇ ÝÞØ ãí ÊæÇäíÏ " & 7 - (i + 1) & " ÏÝÚå ÏíÑ ÇÒ Çíä ÈÑäÇãå ÇÓÊÝÇÏå ˜äíÏ", , "fazell nasiri af soft"
With tNID
.cbSize = Len(tNID)
.hIcon = Me.Icon
.hWnd = Form1.hWnd
.szTip = "Tray icon" & vbCrLf & "revendy.blogfa.com" & vbNullChar
.ucallbackMessage = WM_LBUTTONDOWN
.uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
.uId = 1
End With
Shell_NotifyIcon NIM_ADD, tNID
Print mmosbat
degrees_opt.Value = True
dec_opt.Value = True
txtshow = Val("0") & "."
End Sub
Private Function defaults()
If Val(List1.ListCount) > 0 Then
For i = 0 To Val(List1.ListCount - 1)
List1.RemoveItem i
Next i
Else
End If
If Val(List2.ListCount) > 0 Then
For i = 0 To Val(List2.ListCount - 1)
List2.RemoveItem i
Next i
Else
End If
If Val(List3.ListCount) > 0 Then
For i = 0 To Val(List3.ListCount - 1)
List3.RemoveItem i
Next i
Else
End If
txtshow.Text = Clear
txtshow = Val("0") & "."
af = Clear
bf = Clear
cf = Clear
df = Clear
ef = Clear
md = Clear
not1 = Clear
lch1 = Clear
lm = Clear
ln = Clear
xy = Clear
p = Clear
sinf = Clear
i = Clear
m = Clear
ctrl = Clear
ctrls = cleas
ch1 = Clear
mn = Clear
degrees_opt.Value = True
dec_opt.Value = True
hyp_chk.Value = False
Inv_chk.Value = False
End Function
Private Sub Label3_Click()
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim msg As Long
msg = X / Screen.TwipsPerPixelX
Select Case msg
Case WM_RBUTTONUP
MsgBox "Right click up"
Case WM_LBUTTONDBLCLK
MsgBox "Db-Click"
Case WM_MBUTTONDOWN
MsgBox "Mid click down"
End Select
End Sub
Private Sub Form_Unload(Cancel As Integer)
kk = MsgBox("good like --- ˜ÇÑí ÇÒ ÝÇÖá äÕíÑí !", , "˜ÇÑí ÇÒ ÝÇÖá äÕíÑí")
Shell_NotifyIcon NIM_DELETE, tNID
End Sub
Private Sub gradsmnu_Click()
degreesmenu.Checked = False
radiansmnu.Checked = False
gradsmnu.Checked = True
End Sub
Private Sub hex_opt_Click()
tow.Enabled = True
Command3.Enabled = True
Command4.Enabled = True
Command5.Enabled = True
Command6.Enabled = True
Command7.Enabled = True
Command8.Enabled = True
Command9.Enabled = True
a.Enabled = True
b.Enabled = True
c.Enabled = True
d.Enabled = True
e.Enabled = True
f.Enabled = True
Command33.Enabled = True
End Sub
Private Sub hexmnu_Click()
hexmnu.Checked = True
octal.Checked = False
binary.Checked = False
Decimalmnu.Checked = False
End Sub
Private Sub hpy_chk_Click()
End Sub
Private Sub int_Click()
msg = MsgBox("åäæÒ ˜Ïí ÈÑÇí Çíä Ϙãå äæÔÊå äÔÏå ÇÓÊ !", vbExclamation, "ÎØÇ")
End Sub
Private Sub m_mosbat_Click()
If Val(txtshow.Text) <> 0 Then
Label2.Caption = "M"
End If
mmosbat = Val(txtshow.Text)
ctrls = "m_mosbat"
End Sub
Private Sub mc_Click()
Label2.Caption = Clear
ctrls = Clear
End Sub
Private Sub mod_Click()
md = Val(txtshow.Text)
txtshow = cler
ctrl = 5
End Sub
Private Sub mr_Click()
If Label2.Caption = "M" Then
If ctrl = 1 Then
txtshow.Text = m + mmosbat
ElseIf ctrl = 2 Then
txtshow.Text = List1.List(List1.ListCount - 1) - mmosbat
ElseIf ctrl = 3 Then
txtshow.Text = List2.List(List2.ListCount - 1) * mmosbat
ElseIf ctrl = 4 Then
txtshow.Text = List3.List(List3.ListCount - 1) / mmosbat
Else
txtshow.Text = Clear
txtshow = mmosbat
End If
End If
End Sub
Private Sub not_Click()
not1 = Val(txtshow.Text)
m = -(not1 + 1)
txtshow.Text = m
ctrl = 10
End Sub
Private Sub null_Click()
If ctrl = 4 Then
msg = MsgBox("ÊÞÓíã ÈÑ ÕÝÑ äÇÏÑÓÊ ÇÓÊ", vbExclamation, "Error")
txtshow.Text = 1
Else
txtshow = txtshow & Val("0")
End If
End Sub
Private Sub oct_Click()
End Sub
Private Sub oct_opt_Click()
tow.Enabled = True
Command3.Enabled = True
Command4.Enabled = True
Command5.Enabled = True
Command6.Enabled = True
Command7.Enabled = True
Command8.Enabled = True
Command9.Enabled = True
a.Enabled = False
b.Enabled = False
c.Enabled = False
d.Enabled = False
e.Enabled = False
f.Enabled = False
Command33.Enabled = True
End Sub
Private Sub octal_Click()
hexmnu.Checked = False
octal.Checked = True
binary.Checked = False
Decimalmnu.Checked = False
End Sub
Private Sub one_Click()
If Val(txtshow.Text) = 0 Then
txtshow = Clear
End If
txtshow = txtshow & Val("1")
End Sub
Private Sub Paste_Click()
txtshow = clpboard
End Sub
Private Sub pi_Click()
txtshow.Text = "3.1415926535897932384626433832795"
End Sub
Private Sub radiansmnu_Click()
degreesmenu.Checked = False
radiansmnu.Checked = True
gradsmnu.Checked = False
End Sub
Private Sub s_Click()
txtshow.Text = Clear
End Sub
Private Sub scientific_Click()
Standard.Checked = False
End Sub
Private Sub sin_Click()
p = 4 * Atn(1)
si = Val(txtshow.Text) / 180 * p
End Sub
Private Sub sin_cmd_Click()
If radians_opt.Value = True Then
Const pi = 3.14159265358979
X = 18 * pi / 180
Y = X / Sin(txtshow.Text)
txtshow.Text = Y
If hyp_chk Then
Else
Exit Sub
End If
End If
If hyp_chk Then
txtshow.Text = ((2.7181 ^ Val(txtshow.Text)) - (2.7181 ^ Val(-txtshow.Text))) / 2
Else
p = 4 * Atn(1)
sinf = Val(txtshow.Text) / 180 * p
txtshow.Text = Sin(sinf)
End If
hyp_chk.Value = False
End Sub
Private Sub sta_Click()
Form3.Show
End Sub
Private Sub standard_Click()
Form1.Hide
Form2.Show
Form2.Standard.Checked = True
Form1.Scientific.Checked = False
End Sub
Private Sub Timer1_Timer()
txtshow = Clear
End Sub
Private Sub tan_Click()
End Sub
Private Sub tan_CMD_Click()
If hyp_chk Then
txtshow.Text = (((2.7181 ^ Val(txtshow.Text)) - (2.7181 ^ Val(-txtshow.Text))) / 2) / (((2.7181 ^ Val(txtshow.Text)) + (2.7181 ^ Val(-txtshow.Text))) / 2)
Else
p = 4 * Atn(1)
sinf = Val(txtshow.Text) / 180 * p
txtshow.Text = Tan(sinf)
End If
hyp_chk.Value = False
End Sub
Private Sub tow_Click()
If Val(txtshow.Text) = 0 Then
txtshow = Clear
End If
txtshow = txtshow & Val("2")
End Sub
Private Sub txtshow_Change()
If Len(txtshow.Text) > 0 Then
copy.Enabled = True
End If
End Sub
لطفا سورس به c بدین .
تازه توی این سایت ما چه دلی داشتیم سورس ویروس میذاشتیم . سورس برنامه هایی که زحمت کشیدیم میذاشتیم. پس از این به بعد اسم دنیای open source و آزاد را نیارین . سورس ماشین حساب ساده مثل این نه کسی را بد بخت میکنه نه کسی را پول دار. بلد نیستین بگین بلد نیستیم و الکی واسه بالا رفتن امار تایپیکتون چیزی ننویسین.
اینطوری به نظرم سنگینترین :31:
دوست عزیز این سورس به این درازی رو درون یک فایل آپلود میکردی شاید بهتر بود دستم درد کرد اونقدر اسکرول کردم(شوخی).
خوشحالم که تفکر اوپن سورس داری.
ممنون
نوشتن ماشین حساب کار بسیار ساده ای هست و هیچ ربطی هم به دنیای open source نداره! این بزنامه هم از روز روشن تره که یک پروژه هست. تمام کسانی هم که تکالیفشون رو اینجا از بقیه میپرسن، میگن مال خودم نیست و مال یکی دیگست، یا من این کارا برام کاری نداره... به هر حال، همونطور که مدیر انجمن گفت سورس آماده به کسی داده نمیشه! اینجا هم محل تقلب و دزدی کد و پروژه دانشجویی و دانش آموزی نیست...
خب دوستان . من سورس ماشین حساب پیشرفته به زبان c++ را میگذارم که حتی قادره فرمولی مثل این را حل کنه :
البته بدون هیچ فاصله .کد:5+3.11^2*4*sin(2*3.14)/ln(0)+23.53^6
خب فقط یه مشکلی دارم . میخوام قابلیت حساب کردن درصد را هم بهش اضافه کنم . اگه میشه اینو دیگه بگین . فکر کنم کمک مشکلی نداره . ممنون
این هم سورسش
کد:#include <iostream.h>
#include <fstream.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
void brackets(float[],char*,int,int&);
void operate(float[],char*,int);
void squeeze(float[],char*,int&,int);
void specfunc(float[],char*,int&,int,int);
void strconvert(float*&,char*&,int&,int&);
void strconvert(float*&nexpres,char*&newo,int &nicount,int &oicount)
{
ifstream istring;
ofstream ostring;
ostring.open("cal.dat",ios::out);
char ch;
nicount=0;
int njcount=1;
oicount=0;
//counts all the numbers and operators
do
{
cin.get(ch);
ostring<<ch;
if(isdigit(ch) || ch=='.')
{
nicount++;
cin.get(ch);
ostring<<ch;
for(int tempnj=2;isdigit(ch) || ch=='.' ;tempnj++)
{
if(tempnj>njcount)
{
njcount=tempnj;
}
cin.get(ch);
ostring<<ch;
}
}
if(isalpha(ch))
{
oicount++;
cin.get(ch);
ostring<<ch;
for(;isalpha(ch);)
{
cin.get(ch);
ostring<<ch;
}
}
if(isalnum(ch)==0 && ch!='\n' && ch!='.')
oicount++;
}
while(ch!='\n');
ostring.close();
char **oexpres=new char*[oicount+1]; //+1 for safety
for (int index=0;index<oicount;index++)
{
oexpres[index]=new char[5]; //max asin+1
}
char **numch=new char*[nicount+1];
for (index=0;index<nicount;index++)
{
numch[index]=new char[njcount+1];
}
istring.open("cal.dat",ios::in);
//puts numbers and operators in seperate 2-d strings
int ni=0,oi=0;
do
{
istring.get(ch);
if(isdigit(ch) || ch=='.' && ni<nicount)
{
numch[ni][0]=ch;
istring.get(ch);
for(int nj=1;isdigit(ch) || ch=='.' && nj<njcount;nj++)
{
numch[ni][nj]=ch;
istring.get(ch);
}
ni++;
}
if(isalpha(ch))
{
oexpres[oi][0]=ch;
istring.get(ch);
for(int oj=1;isalpha(ch) && oj<4;oj++)
{
oexpres[oi][oj]=ch;
istring.get(ch);
}
oi++;
}
if(isalnum(ch)==0 && ch!='.' && ch!='\n' && oi<oicount)
{
oexpres[oi][0]=ch;
oi++;
}
}
while(ch!='\n');
//converts number string to float a string
nexpres=new float[nicount];
for(index=0;index<nicount;index++)
{
nexpres[index]=atof(numch[index]);
}
newo=new char[oicount+1];
for(index=0;index<oicount;index++)
{
if (isalpha(oexpres[index][0]))
{
if(strncmp(oexpres[index],"sin",3)==0)
{oexpres[index][0]='s';}
else if(strncmp(oexpres[index],"cos",3)==0)
{oexpres[index][0]='c';}
else if(strncmp(oexpres[index],"tan",3)==0)
{oexpres[index][0]='t';}
else if(strncmp(oexpres[index],"asin",4)==0)
{oexpres[index][0]='i';}
else if(strncmp(oexpres[index],"acos",4)==0)
{oexpres[index][0]='o';}
else if(strncmp(oexpres[index],"atan",4)==0)
{oexpres[index][0]='a';}
else if(strncmp(oexpres[index],"log",3)==0)
{oexpres[index][0]='g';}
else if(strncmp(oexpres[index],"ln",2)==0)
{oexpres[index][0]='n';}
else if(strncmp(oexpres[index],"exp",3)==0)
{oexpres[index][0]='e';}
else if(strncmp(oexpres[index],"abs",3)==0)
{oexpres[index][0]='b';}
else if(strncmp(oexpres[index],"sqrt",4)==0)
{oexpres[index][0]='q';}
}
newo[index]=oexpres[index][0];
}
}
void brackets(float nexpres[],char *oexpres,int nxindex,int &oxindex)
{
int bcount=0;
for(int i=0;i<oxindex;i++) //counts times to perform funtion
{
if (oexpres[i]==')')
bcount++;
}
for(int braks=0;braks<bcount;braks++)
{
int end=0;
for(;oexpres[end]!=')';end++)
{}
int begin=end;
for(;oexpres[begin]!='(';begin--)
{}
float *number=new float[end-begin];
char *operators=new char[end-begin]; // chars+ '/0'
int numpos=0;
for(int i=0;i<begin;i++) //for nested brackets
{
if (oexpres[i]=='(' || isalpha(oexpres[i]))
numpos++;
}
i=0;
for(int k=(begin-numpos);k<(end-numpos);k++) //load up number with bracket elements
number[i++]=nexpres[k];
for(k=begin+1,i=0;k<end;k++)
operators[i++]=oexpres[k]; //load up with operators
operate(number,operators,(end-begin-1));
nexpres[begin-numpos]=number[0];
int j=(begin-numpos+1);
for(i=(end-numpos);i<nxindex;i++)
nexpres[j++]=nexpres[i];
for(i=end+1,j=begin;i<oxindex;i++)
oexpres[j++]=oexpres[i];
nxindex-=(end-begin-1);
oxindex-=(end-begin+1);
if(isalpha(oexpres[begin-1]))
specfunc(nexpres,oexpres,oxindex,begin,numpos);
}
}
void operate(float number[],char*operators,int oindex)
{
const char* orderof="^/*-+";
for(int k=0;k<5;k++) //changes operator according to precedence
{
for(int i=0;i<oindex;i++) //marches through the statement
{
if(operators[i]==orderof[k]) //checks for desired operator
{
switch(operators[i]) //conducts the operation
{
case '^':number[i]=pow(number[i],number[i+1]);break;
case '*':number[i]*=number[i+1];break;
case '/':number[i]/=number[i+1];break;
case '+':number[i]+=number[i+1];break;
case '-':number[i]-=number[i+1];break;
}
squeeze(number,operators,oindex,(i+1)); //squeezeout (i+1)
if(oindex==1)
i--;
if(i!=(oindex-1)) //re-test same index with new 'squeezed' values
i--;
}
}
}
}
void squeeze(float number[],char*operators,int &oindex,int squeezeout)
{//sqeezes remaining operation together, maintains integrity of loop
for(int j=squeezeout;j<oindex;j++)
{
number[j]=number[j+1];
operators[j-1]=operators[j];
}
oindex--;
}
void specfunc
(float nexpres[],char *oexpres,int &oxindex,int begin,int numpos)
{
switch(oexpres[begin-1])
{
case 's':nexpres[begin-numpos]=sin(nexpres[begin-numpos]);break;
case 'c':nexpres[begin-numpos]=cos(nexpres[begin-numpos]);break;
case 't':nexpres[begin-numpos]=tan(nexpres[begin-numpos]);break;
case 'i':nexpres[begin-numpos]=asin(nexpres[begin-numpos]);break;
case 'o':nexpres[begin-numpos]=acos(nexpres[begin-numpos]);break;
case 'a':nexpres[begin-numpos]=atan(nexpres[begin-numpos]);break;
case 'g':nexpres[begin-numpos]=log10(nexpres[begin-numpos]);break;
case 'n':nexpres[begin-numpos]=log(nexpres[begin-numpos]);break;
case 'e':nexpres[begin-numpos]=exp(nexpres[begin-numpos]);break;
case 'b':nexpres[begin-numpos]=abs(nexpres[begin-numpos]);break;
case 'q':nexpres[begin-numpos]=sqrt(nexpres[begin-numpos]);break;
}
for(int j=begin;j<oxindex;j++)
oexpres[j-1]=oexpres[j];
oxindex--;
}
void main()
{
float *nexpres;
char *oexpres;
int nxindex,oxindex;
cout<<"//all calculations are in radians"<<endl<<endl;
cout<<"calculate->";
strconvert(nexpres,oexpres,nxindex,oxindex);
brackets(nexpres,oexpres,nxindex,oxindex);
operate(nexpres,oexpres,oxindex);
cout<<"="<<nexpres[0];
//to view all elements
//for(int i=0;i<nxindex;i++)
//cout<<nexpres[i]<<" ";
//cout<<endl;
//for(int i=0;i<oxindex;i++)
//cout<<oexpres[i];
//cout<<endl;
cin.ignore(128, '\n');
}
دل اونایی که open source نیستن بسوزه :31:
اين برنامه به زبان فارسيه ؟نقل قول:
ضمنا شما برنامه کنسول که نمي خواين . مي خواين ؟
راستي چرا هميشه وقتي سورس و راهنمايي مي خواين هميشه با دعوا و مرافه ؟ با ملايمت هم ميشه . :46:
خوب ظاهرا شما دقيقا اينو از جايي کپي کردين و گذاشتين و خودتون يک بار هم امتحان نکردين که ببينين برنامه درسته يا نه و اصلا چيکار مي کنه و اين فرمولي رو که گفتين واقعا حل ميکنه يا نه .نقل قول:
چون من که زدم 102 تا ارور داد . چرا با اين قاطعيت از برنامه اي که خودتون هم نمي دونين توش چيه و اصلا ماشين حساب هست يا کد سيستم عامله دفاع مي کنين و به قول خودتون close source ها رو مورد خطاب قرار مي دين ؟ :13:
عزیزم کامپایار میدونی چیه ؟ کامپایلرت نسخش فرق میکنه مهندس . من که بدون هیچ مشکلی باهاش کار کردم .
دوما به کسی مربوط نیست که کپی کردم یا نه . سوما بلدی بگو نیستی خوش اومدی .
چهارما کامپایلر میدونی چیه ؟ :D
این برنامه با borland کامپایل میشه برای visual باید تغییراتی توش بدید ضمن این که چند جا متغییر تعریف نشده به همین دلیل ارور داده من تغییر دادم مشکلی نداره
کد:// C++.cpp : main project file.
#include "stdafx.h"
using namespace System;
#include "iostream"
#include "fstream"
#include "string"
#include "ctype.h"
#include "stdlib.h"
#include "math.h"
using namespace std;
using namespace IO;
void brackets(float[],char*,int,int&);
void operate(float[],char*,int);
void squeeze(float[],char*,int&,int);
void specfunc(float[],char*,int&,int,int);
void strconvert(float*&,char*&,int&,int&);
void strconvert(float*&nexpres,char*&newo,int &nicount,int &oicount)
{
// a:
ifstream istring;
ofstream ostring;
ostring.open("cal.dat",ios::out);
char ch;
nicount=0;
int njcount=1;
oicount=0;
//counts all the numbers and operators
do
{
cin.get(ch);
ostring<<ch;
if(isdigit(ch) || ch=='.')
{
nicount++;
cin.get(ch);
ostring<<ch;
for(int tempnj=2;isdigit(ch) || ch=='.' ;tempnj++)
{
if(tempnj>njcount)
{
njcount=tempnj;
}
cin.get(ch);
ostring<<ch;
}
}
if(isalpha(ch))
{
oicount++;
cin.get(ch);
ostring<<ch;
for(;isalpha(ch);)
{
cin.get(ch);
ostring<<ch;
}
}
if(isalnum(ch)==0 && ch!='\n' && ch!='.')
oicount++;
}
while(ch!='\n');
ostring.close();
char **oexpres=new char*[oicount+1]; //+1 for safety
for (int index=0;index<oicount;index++)
{
oexpres[index]=new char[5]; //max asin+1
}
char **numch=new char*[nicount+1];
for (int index=0;index<nicount;index++)
{
numch[index]=new char[njcount+1];
}
istring.open("cal.dat",ios::in);
//puts numbers and operators in seperate 2-d strings
int ni=0,oi=0;
do
{
istring.get(ch);
if(isdigit(ch) || ch=='.' && ni<nicount)
{
numch[ni][0]=ch;
istring.get(ch);
for(int nj=1;isdigit(ch) || ch=='.' && nj<njcount;nj++)
{
numch[ni][nj]=ch;
istring.get(ch);
}
ni++;
}
if(isalpha(ch))
{
oexpres[oi][0]=ch;
istring.get(ch);
for(int oj=1;isalpha(ch) && oj<4;oj++)
{
oexpres[oi][oj]=ch;
istring.get(ch);
}
oi++;
}
if(isalnum(ch)==0 && ch!='.' && ch!='\n' && oi<oicount)
{
oexpres[oi][0]=ch;
oi++;
}
}
while(ch!='\n');
//converts number string to float a string
nexpres=new float[nicount];
for(int index=0;index<nicount;index++)
{
nexpres[index]=atof(numch[index]);
}
newo=new char[oicount+1];
for(int index=0;index<oicount;index++)
{
if (isalpha(oexpres[index][0]))
{
if(strncmp(oexpres[index],"sin",3)==0)
{oexpres[index][0]='s';}
else if(strncmp(oexpres[index],"cos",3)==0)
{oexpres[index][0]='c';}
else if(strncmp(oexpres[index],"tan",3)==0)
{oexpres[index][0]='t';}
else if(strncmp(oexpres[index],"asin",4)==0)
{oexpres[index][0]='i';}
else if(strncmp(oexpres[index],"acos",4)==0)
{oexpres[index][0]='o';}
else if(strncmp(oexpres[index],"atan",4)==0)
{oexpres[index][0]='a';}
else if(strncmp(oexpres[index],"log",3)==0)
{oexpres[index][0]='g';}
else if(strncmp(oexpres[index],"ln",2)==0)
{oexpres[index][0]='n';}
else if(strncmp(oexpres[index],"exp",3)==0)
{oexpres[index][0]='e';}
else if(strncmp(oexpres[index],"abs",3)==0)
{oexpres[index][0]='b';}
else if(strncmp(oexpres[index],"sqrt",4)==0)
{oexpres[index][0]='q';}
}
newo[index]=oexpres[index][0];
}
}
void brackets(float nexpres[],char *oexpres,int nxindex,int &oxindex)
{
int bcount=0;
for(int i=0;i<oxindex;i++) //counts times to perform funtion
{
if (oexpres[i]==')')
bcount++;
}
for(int braks=0;braks<bcount;braks++)
{
int end=0;
for(;oexpres[end]!=')';end++)
{}
int begin=end;
for(;oexpres[begin]!='(';begin--)
{}
float *number=new float[end-begin];
char *operators=new char[end-begin]; // chars+ '/0'
int numpos=0;
int i;
for(int i=0;i<begin;i++) //for nested brackets
{
if (oexpres[i]=='(' || isalpha(oexpres[i]))
numpos++;
}
i=0;
for(int k=(begin-numpos);k<(end-numpos);k++) //load up number with bracket elements
number[i++]=nexpres[k];
for(int k=begin+1,i=0;k<end;k++)
operators[i++]=oexpres[k]; //load up with operators
operate(number,operators,(end-begin-1));
nexpres[begin-numpos]=number[0];
int j=(begin-numpos+1);
for(i=(end-numpos);i<nxindex;i++)
nexpres[j++]=nexpres[i];
for(i=end+1,j=begin;i<oxindex;i++)
oexpres[j++]=oexpres[i];
nxindex-=(end-begin-1);
oxindex-=(end-begin+1);
if(isalpha(oexpres[begin-1]))
specfunc(nexpres,oexpres,oxindex,begin,numpos);
}
}
void operate(float number[],char*operators,int oindex)
{
const char* orderof="^/*-+";
for(int k=0;k<5;k++) //changes operator according to precedence
{
for(int i=0;i<oindex;i++) //marches through the statement
{
if(operators[i]==orderof[k]) //checks for desired operator
{
switch(operators[i]) //conducts the operation
{
case '^':number[i]=pow(number[i],number[i+1]);break;
case '*':number[i]*=number[i+1];break;
case '/':number[i]/=number[i+1];break;
case '+':number[i]+=number[i+1];break;
case '-':number[i]-=number[i+1];break;
}
squeeze(number,operators,oindex,(i+1)); //squeezeout (i+1)
if(oindex==1)
i--;
if(i!=(oindex-1)) //re-test same index with new 'squeezed' values
i--;
}
}
}
}
void squeeze(float number[],char*operators,int &oindex,int squeezeout)
{//sqeezes remaining operation together, maintains integrity of loop
for(int j=squeezeout;j<oindex;j++)
{
number[j]=number[j+1];
operators[j-1]=operators[j];
}
oindex--;
}
void specfunc
(float nexpres[],char *oexpres,int &oxindex,int begin,int numpos)
{
switch(oexpres[begin-1])
{
case 's':nexpres[begin-numpos]=sin(nexpres[begin-numpos]);break;
case 'c':nexpres[begin-numpos]=cos(nexpres[begin-numpos]);break;
case 't':nexpres[begin-numpos]=tan(nexpres[begin-numpos]);break;
case 'i':nexpres[begin-numpos]=asin(nexpres[begin-numpos]);break;
case 'o':nexpres[begin-numpos]=acos(nexpres[begin-numpos]);break;
case 'a':nexpres[begin-numpos]=atan(nexpres[begin-numpos]);break;
case 'g':nexpres[begin-numpos]=log10(nexpres[begin-numpos]);break;
case 'n':nexpres[begin-numpos]=log(nexpres[begin-numpos]);break;
case 'e':nexpres[begin-numpos]=exp(nexpres[begin-numpos]);break;
case 'b':nexpres[begin-numpos]=abs(nexpres[begin-numpos]);break;
case 'q':nexpres[begin-numpos]=sqrt(nexpres[begin-numpos]);break;
}
for(int j=begin;j<oxindex;j++)
oexpres[j-1]=oexpres[j];
oxindex--;
}
void main()
{
float *nexpres;
char *oexpres;
int nxindex,oxindex;
cout<<"//all calculations are in radians"<<endl<<endl;
cout<<"calculate->";
strconvert(nexpres,oexpres,nxindex,oxindex);
brackets(nexpres,oexpres,nxindex,oxindex);
operate(nexpres,oexpres,oxindex);
cout<<"="<<nexpres[0];
//to view all elements
//for(int i=0;i<nxindex;i++)
//cout<<nexpres[i]<<" ";
//cout<<endl;
//for(int i=0;i<oxindex;i++)
//cout<<oexpres[i];
//cout<<endl;
cin.ignore(128, '\n');
}
:31: :31:نقل قول:
بنده متاسفانه نمي دونم کامپايلر يعني چي . ببخشيد . واقعا عذر مي خوام .
حالا مطمئن شدم برنامه رو تست نکردين .
دکتر !!!! هيچ وقت براي يه هدر فايل 102 تا ارور داده نمي شه . اگه نتونست هدر فايل رو بشناسه 1 ارور مي ده و اجراي برنامه همون جا مي مونه . (چون پيش پردازنده قبل از کامپايل برنامه اجرا ميشه ! :46: )
هيچ وقت تو ++C وقتي مي خوان در مورد Syntax ارور برنامه حرف بزنن سراغ هدر و ;using namespace std نمي رن . همه مي دونن برنامه تو توربو سي چطور اجرا ميشه و تو Visual Studio چطور . مشکل شما همون تعريف متغيرها بود که دوست عزيزمون m_h_hadavi هم اشاره کردن .
مي دونم تعريف متغير مسئله مهمي تو برنامه نويسي نيست ولي بالاخره مهم اينه که باعث ميشه برنامه اجرا نشه . منظور من هم از مطرح کردن ايراد برنامه اين بود که ثابت کنم شما برنامه رو همين جوري گذاشتي و تست نکردي . :31:
حالا فرض کن من اون اضافاتي رو که گفتي اعمال کردم ( درصد و اينا ) ، شما از کجا مي فهمي که درسته يا نه ؟
موفق باشي پروفسور ...............
اين هم کد کامل اين برنامه که مشکل متغير ها هم جل شد و چند تا Warning هم داشت ( 9 تا ) که اونا رو هم حل کردم . با استفاده از Tab و اينا هم خوندن برنامه آسان تر شده ( براي کسايي که مي خوان توسعه اش بدن )
;using namespace IO و ;using namespace systemبرام نياز نشدن . اينا براي چي هستن ؟
[html]
#include <iostream>
#include <fstream>
#include <string>
#include <cctype>
#include <cstdlib>
#include <cmath>
using namespace std;
void brackets ( double [], char *, int, int & );
void operate ( double [], char *, int );
void squeeze ( double [], char *, int &, int );
void specfunc ( double [], char *, int &, int, int );
void strconvert ( double *&, char *&, int &, int & );
int main ()
{
double *nexpres;
char *oexpres;
int nxindex, oxindex;
cout << "//all calculations are in radians\n\n";
cout << "calculate->";
strconvert ( nexpres, oexpres, nxindex, oxindex );
brackets ( nexpres, oexpres, nxindex, oxindex );
operate ( nexpres, oexpres, oxindex );
cout << "=" << nexpres [ 0 ];
cin.ignore ( 128, '\n');
return 0;
}
void strconvert ( double *&nexpres, char *&newo, int &nicount, int &oicount )
{
ifstream istring;
ofstream ostring;
ostring.open ( "cal.dat", ios::out );
char ch;
nicount = 0;
int njcount = 1;
oicount = 0;
do
{
cin.get ( ch );
ostring << ch;
if ( isdigit ( ch ) || ch == '.' )
{
nicount++;
cin.get ( ch );
ostring << ch;
for ( int tempnj = 2; isdigit ( ch ) || ch == '.'; tempnj++ )
{
if ( tempnj > njcount )
{
njcount = tempnj;
}
cin.get ( ch );
ostring << ch;
}
}
if ( isalpha ( ch ) )
{
oicount++;
cin.get ( ch );
ostring << ch;
for ( ; isalpha ( ch ); )
{
cin.get ( ch );
ostring << ch;
}
}
if ( isalnum ( ch ) == 0 && ch != '\n' && ch != '.' )
oicount++;
} while ( ch != '\n' );
ostring.close ();
char **oexpres = new char * [ oicount + 1 ];
for ( int index = 0; index < oicount; index++ )
{
oexpres [ index ] = new char [ 5 ];
}
char **numch = new char * [ nicount + 1 ];
for ( int index = 0; index < nicount; index++ )
{
numch [ index ] = new char [ njcount + 1 ];
}
istring.open ( "cal.dat", ios::in );
int ni = 0, oi = 0;
do
{
istring.get ( ch );
if ( isdigit ( ch ) || ch == '.' && ni < nicount )
{
numch [ ni ][ 0 ] = ch;
istring.get ( ch );
for ( int nj = 1; isdigit ( ch ) || ch == '.' && nj < njcount; nj++ )
{
numch [ ni ][ nj ] = ch;
istring.get ( ch );
}
ni++;
}
if ( isalpha ( ch ) )
{
oexpres [ oi ][ 0 ] = ch;
istring.get ( ch );
for ( int oj = 1; isalpha ( ch ) && oj < 4; oj++ )
{
oexpres [ oi ][ oj ] = ch;
istring.get ( ch );
}
oi++;
}
if ( isalnum ( ch ) == 0 && ch != '.' && ch != '\n' && oi < oicount )
{
oexpres [ oi ][ 0 ] = ch;
oi++;
}
} while ( ch != '\n' );
nexpres = new double [ nicount ];
for ( int index = 0; index < nicount; index++ )
{
nexpres [ index ] = atof ( numch [ index ] );
}
newo = new char [ oicount + 1 ];
for ( int index = 0; index < oicount; index++ )
{
if ( isalpha ( oexpres [ index ][ 0 ] ) )
{
if ( strncmp ( oexpres [ index ], "sin", 3 ) == 0 )
oexpres [ index ][ 0 ] = 's';
else if ( strncmp ( oexpres [ index ], "cos", 3 ) == 0 )
oexpres [ index ][ 0 ] = 'c';
else if ( strncmp ( oexpres [ index ], "tan", 3 ) == 0 )
oexpres [ index ][ 0 ] = 't';
else if ( strncmp ( oexpres [ index ], "asin", 4 ) == 0 )
oexpres [ index ][ 0 ] = 'i';
else if ( strncmp ( oexpres [ index ], "acos", 4 ) == 0 )
oexpres [ index ][ 0 ] = 'o';
else if ( strncmp ( oexpres [ index ], "atan", 4 ) == 0 )
oexpres [ index ][ 0 ] = 'a';
else if ( strncmp ( oexpres [ index ], "log", 3 ) == 0 )
oexpres [ index ][ 0 ] = 'g';
else if ( strncmp ( oexpres [ index ], "ln", 2 ) == 0 )
oexpres [ index ][ 0 ] = 'n';
else if ( strncmp ( oexpres [ index ], "exp", 3 ) == 0 )
oexpres [ index ][ 0 ] = 'e';
else if ( strncmp ( oexpres [ index ], "abs", 3 ) == 0 )
oexpres [ index ][ 0 ] = 'b';
else if ( strncmp ( oexpres [ index ], "sqrt", 4 ) == 0 )
oexpres [ index ][ 0 ] = 'q';
}
newo [ index ] = oexpres [ index ][ 0 ];
}
}
void brackets(double nexpres[],char *oexpres,int nxindex,int &oxindex)
{
int bcount = 0;
int i, k;
for ( i = 0; i < oxindex; i++ )
{
if ( oexpres [ i ] == ')' )
bcount++;
}
for ( int braks = 0; braks < bcount; braks++ )
{
int end = 0;
for ( ; oexpres [ end ] != ')'; end++ )
{
}
int begin = end;
for ( ; oexpres [ begin ] != '('; begin-- )
{
}
double *number = new double [ end - begin ];
char *operators = new char [ end - begin ];
int numpos = 0;
for ( i = 0; i < begin; i++ )
{
if ( oexpres [ i ] == '(' || isalpha ( oexpres [ i ] ) )
numpos++;
}
i = 0;
for ( k = ( begin - numpos ); k < ( end - numpos ); k++ )
number [ i++ ] = nexpres [ k ];
for ( k = begin + 1, i = 0; k < end; k++ )
operators [ i++ ] = oexpres [ k ];
operate ( number, operators, ( end - begin - 1 ) );
nexpres [ begin - numpos ] = number [ 0 ];
int j = ( begin - numpos + 1 );
for ( i = ( end - numpos ); i < nxindex; i++ )
nexpres [ j++ ] = nexpres [ i ];
for ( i = end + 1, j = begin; i < oxindex; i++ )
oexpres [ j++ ] = oexpres [ i ];
nxindex -= ( end - begin - 1 );
oxindex -= ( end - begin + 1 );
if ( isalpha ( oexpres [ begin - 1 ] ) )
specfunc ( nexpres, oexpres, oxindex, begin, numpos );
}
}
void operate ( double number [], char *operators, int oindex )
{
const char *orderof = "^/*-+";
for ( int k = 0; k < 5; k++ )
{
for ( int i = 0; i < oindex; i++ )
{
if ( operators [ i ] == orderof [ k ] )
{
switch ( operators [ i ] )
{
case '^':
number [ i ] = pow ( number [ i ], number [ i + 1 ] );
break;
case '*':
number [ i ] *= number [ i + 1 ];
break;
case '/':
number [ i ] /= number [ i + 1 ];
break;
case '+':
number [ i ] += number [ i + 1 ];
break;
case '-':
number [ i ] -= number [ i + 1 ];
break;
}
squeeze ( number, operators, oindex, ( i + 1 ) );
if ( oindex == 1 )
i--;
if ( i != ( oindex - 1 ) )
i--;
}
}
}
}
void squeeze ( double number [], char *operators, int &oindex, int squeezeout )
{
for ( int j = squeezeout; j < oindex; j++ )
{
number [ j ] = number [ j + 1 ];
operators [ j - 1 ] = operators [ j ];
}
oindex--;
}
void specfunc ( double nexpres [], char *oexpres, int &oxindex, int begin, int numpos )
{
switch ( oexpres [ begin - 1 ] )
{
case 's':
nexpres [ begin - numpos ] = sin ( nexpres [ begin - numpos ] );
break;
case 'c':
nexpres [ begin - numpos ] = cos ( nexpres [ begin - numpos ] );
break;
case 't':
nexpres [ begin - numpos ] = tan ( nexpres [ begin - numpos ] );
break;
case 'i':
nexpres [ begin - numpos ] = asin ( nexpres [ begin - numpos ] );
break;
case 'o':
nexpres [ begin - numpos ] = acos ( nexpres [ begin - numpos ] );
break;
case 'a':
nexpres [ begin - numpos ] = atan ( nexpres [ begin - numpos ] );
break;
case 'g':
nexpres [ begin - numpos ] = log10 ( nexpres [ begin - numpos ] );
break;
case 'n':
nexpres [ begin - numpos ] = log ( nexpres [ begin - numpos ] );
break;
case 'e':
nexpres [ begin - numpos ] = exp ( nexpres [ begin - numpos ] );
break;
case 'b':
nexpres [ begin - numpos ] = abs ( nexpres [ begin - numpos ] );
break;
case 'q':
nexpres [ begin - numpos ] = sqrt ( nexpres [ begin - numpos ] );
break;
}
for ( int j = begin; j < oxindex; j++ )
oexpres [ j - 1 ] = oexpres [ j ];
oxindex--;
}
[/html]
شما از چه کامپایلری استفاده کردید من از visual 2005 استفاده کردم
برای استفاده از توابع fstream و .. باید using namespace IO;
رو تعریف کرد
using namespace System; هم اضافی هست
من هم از 2008 . نسخه Professional . شما وقتي نمي ذارين ارور ميده ؟نقل قول:
بلهنقل قول:
من بیشتر با C++ Builder 2009 کار کردم اونجا نیاز نیست IO رو هم گشتم پیدا کردم تا به حال ازش استفاده نکرده بودم
به گفته دوست عزیزمان برنامه 9 تا ارور داشت اون هم برای تعریف متغیر بوده . یک متغیر چند جا تعریف شده بود . مشکلش را حل کرده بودم . ولی مثل اینکه کد قدیمی را گذاشته بودم .
و اگه شما درصد را توش بذارین و بگین چطور میشه ازش استفاده کرد بسیار ممنون میشیم. همین . سخته ؟ یا میشه ؟
سلام
دوستان میتونید منو راهنمایی کنید چجوری میتونم یه ماشین حساب ساده با c++ بنویسم ؟؟؟
فقط بتونه با عملگرهای اصلی مثل جمع و تفریق بتونه یه عبارت رو محاسبه کنه ....
برای یاد گیری میخوام میتونید کمک کنید یا سورسشو قرار بدید ؟
با کدهای ساده چون تازه با این زبان آشنا شدم و با کدهای پیشرفته و دستورات پیچیده آشنایی ندارم
دوستان خواهشا کمک کنید ....