Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Console Calculator
WhatsApp
Igor Djuricic
Oct 24
2014
1.9
k
0
1
ConsoleApplication6_
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
ConsoleApplication6;
namespace
ConsoleApplication6 {
public
class
MojaKlasa {
public
const
double
const_PI = 3.14;
public
readonly
double
readOnly_PI;
public
MojaKlasa() {
readOnly_PI = 3.14;
}
}
public
class
MojKrug: MojaKlasa {
public
double
PI = 3.14;
public
double
op1;
public
double
area() {
return
op1 * op1 * PI;
}
}
class
Kalkulator {
public
int
op1;
public
int
op2;
public
double
add() {
return
op1 + op2;
}
public
double
sub() {
return
op1 - op2;
}
public
double
mul() {
return
op1 * op2;
}
public
double
div() {
return
op1 / op2;
}
public
void
Operands(
int
op1,
int
op2) {
this
.op1 = op1;
this
.op2 = op2;
}
}
class
Program {
static
void
Main(
string
[] args) {
MojKrug k =
new
MojKrug();
Console.Write(
"Operand 1: "
);
k.op1 = Convert.ToInt32(Console.ReadLine());
System.Console.WriteLine(k.area());
Kalkulator c =
new
Kalkulator();
Console.Write(
"Operand 1: "
);
c.op1 = Convert.ToInt32(Console.ReadLine());
Console.Write(
"Operand 2: "
);
c.op2 = Convert.ToInt32(Console.ReadLine());
Console.Write(
"Operator : "
);
string
oper = Console.ReadLine();
switch
(oper) {
case
"+"
:
Console.WriteLine(c.add());
break
;
case
"-"
:
Console.WriteLine(c.sub());
break
;
case
"*"
:
Console.WriteLine(c.mul());
break
;
case
"/"
:
Console.WriteLine(c.div());
break
;
}
}
}
}
C#
OOP
Up Next
Console Calculator