TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Console Calculator
Igor Đuričić
Oct 24
2014
Code
1.8
k
0
1
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
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