SlideShare a Scribd company logo
C# 6
Write a program that creates a Calculation Class
Use the following Code and Implement as a class.
using System.IO;
using System;
class Program
{
static void Main()
{
int first, second;
Console.WriteLine("Enter first number: ");
first=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter second number: ");
second=Convert.ToInt32(Console.ReadLine());
int sum = add(first, second);
Console.WriteLine("The sum is "+sum);
}
static int add(int a, int b){
int sum = 0;
sum = a + b;
return sum;
}
}
The class will have properties for the two numbers the user inputs
The class will have methods to:
Prompt the user to input two numbers
Output results
YOU WILL NEED TO IMPLEMENT ERROR HANDLING IN CASE OF BAD INPUT!
Solution
# include using namespace std; int main() { char o; float num1,num2; cout << "Enter
operator either + or - or * or /: "; cin >> o; cout << "Enter two operands: "; cin >>
num1 >> num2; switch(o) { case '+': cout << num1+num2; break;
case '-': cout << num1-num2; break; case '*': cout << num1*num2;
break; case '/': cout << num1/num2; break; default: /* If
operator is other than +, -, * or /, error message is shown */ cout << "Error! operator is
not correct"; break; } return 0; }

More Related Content

Similar to C# 6Write a program that creates a Calculation ClassUse the foll.pdf

Lab101.pptx
Lab101.pptxLab101.pptx
Lab101.pptx
KimVeeL
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
mayorothenguyenhob69
 
.net progrmming part2
.net progrmming part2.net progrmming part2
.net progrmming part2
Dr.M.Karthika parthasarathy
 
Seminar 2 coding_principles
Seminar 2 coding_principlesSeminar 2 coding_principles
Seminar 2 coding_principles
moduledesign
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cpp
Nilesh Dalvi
 
Codeimport java.util.Random; import java.util.Scanner;public .pdf
Codeimport java.util.Random; import java.util.Scanner;public .pdfCodeimport java.util.Random; import java.util.Scanner;public .pdf
Codeimport java.util.Random; import java.util.Scanner;public .pdf
anupamfootwear
 
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
bhargavi804095
 
Assignment Java Programming 2
Assignment Java Programming 2Assignment Java Programming 2
Assignment Java Programming 2
Kaela Johnson
 
Practical basics on c++
Practical basics on c++Practical basics on c++
Practical basics on c++
Marco Izzotti
 
basics of C and c++ by eteaching
basics of C and c++ by eteachingbasics of C and c++ by eteaching
basics of C and c++ by eteaching
eteaching
 
Lecture2.ppt
Lecture2.pptLecture2.ppt
Lecture2.ppt
TarekHemdan3
 
07-Basic-Input-Output.ppt
07-Basic-Input-Output.ppt07-Basic-Input-Output.ppt
07-Basic-Input-Output.ppt
Ajenkris Kungkung
 
keyword
keywordkeyword
keyword
teach4uin
 
keyword
keywordkeyword
keyword
teach4uin
 
OXUS20 JAVA Programming Questions and Answers PART I
OXUS20 JAVA Programming Questions and Answers PART IOXUS20 JAVA Programming Questions and Answers PART I
OXUS20 JAVA Programming Questions and Answers PART I
Abdul Rahman Sherzad
 
39927902 c-labmanual
39927902 c-labmanual39927902 c-labmanual
39927902 c-labmanual
Srinivasa Babji Josyula
 
python lab programs.pdf
python lab programs.pdfpython lab programs.pdf
python lab programs.pdf
CBJWorld
 
programming for Calculator in java
programming for Calculator in javaprogramming for Calculator in java
programming for Calculator in java
One97 Communications Limited
 

Similar to C# 6Write a program that creates a Calculation ClassUse the foll.pdf (20)

Lab101.pptx
Lab101.pptxLab101.pptx
Lab101.pptx
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
 
.net progrmming part2
.net progrmming part2.net progrmming part2
.net progrmming part2
 
Output
OutputOutput
Output
 
Seminar 2 coding_principles
Seminar 2 coding_principlesSeminar 2 coding_principles
Seminar 2 coding_principles
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cpp
 
Codeimport java.util.Random; import java.util.Scanner;public .pdf
Codeimport java.util.Random; import java.util.Scanner;public .pdfCodeimport java.util.Random; import java.util.Scanner;public .pdf
Codeimport java.util.Random; import java.util.Scanner;public .pdf
 
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
 
Assignment Java Programming 2
Assignment Java Programming 2Assignment Java Programming 2
Assignment Java Programming 2
 
Practical basics on c++
Practical basics on c++Practical basics on c++
Practical basics on c++
 
basics of C and c++ by eteaching
basics of C and c++ by eteachingbasics of C and c++ by eteaching
basics of C and c++ by eteaching
 
Lecture2.ppt
Lecture2.pptLecture2.ppt
Lecture2.ppt
 
07-Basic-Input-Output.ppt
07-Basic-Input-Output.ppt07-Basic-Input-Output.ppt
07-Basic-Input-Output.ppt
 
keyword
keywordkeyword
keyword
 
keyword
keywordkeyword
keyword
 
OXUS20 JAVA Programming Questions and Answers PART I
OXUS20 JAVA Programming Questions and Answers PART IOXUS20 JAVA Programming Questions and Answers PART I
OXUS20 JAVA Programming Questions and Answers PART I
 
39927902 c-labmanual
39927902 c-labmanual39927902 c-labmanual
39927902 c-labmanual
 
39927902 c-labmanual
39927902 c-labmanual39927902 c-labmanual
39927902 c-labmanual
 
python lab programs.pdf
python lab programs.pdfpython lab programs.pdf
python lab programs.pdf
 
programming for Calculator in java
programming for Calculator in javaprogramming for Calculator in java
programming for Calculator in java
 

More from ssuserc77a341

A T1 uses which of the following to multiplex DS0s into a composite .pdf
A T1 uses which of the following to multiplex DS0s into a composite .pdfA T1 uses which of the following to multiplex DS0s into a composite .pdf
A T1 uses which of the following to multiplex DS0s into a composite .pdf
ssuserc77a341
 
Can you solve this question please!! 7. The proportion of the solar .pdf
Can you solve this question please!! 7. The proportion of the solar .pdfCan you solve this question please!! 7. The proportion of the solar .pdf
Can you solve this question please!! 7. The proportion of the solar .pdf
ssuserc77a341
 
CAN and TTP are the two wired network protocols used for distributed .pdf
CAN and TTP are the two wired network protocols used for distributed .pdfCAN and TTP are the two wired network protocols used for distributed .pdf
CAN and TTP are the two wired network protocols used for distributed .pdf
ssuserc77a341
 
34. Cam is a mechanical device that transforms rotary motion into lin.pdf
34. Cam is a mechanical device that transforms rotary motion into lin.pdf34. Cam is a mechanical device that transforms rotary motion into lin.pdf
34. Cam is a mechanical device that transforms rotary motion into lin.pdf
ssuserc77a341
 
1. What is the role of mediator Is it in prokaryotes or eukaryotes..pdf
1. What is the role of mediator Is it in prokaryotes or eukaryotes..pdf1. What is the role of mediator Is it in prokaryotes or eukaryotes..pdf
1. What is the role of mediator Is it in prokaryotes or eukaryotes..pdf
ssuserc77a341
 
Could someone read over this paper and tell me how it reads so far a.pdf
Could someone read over this paper and tell me how it reads so far a.pdfCould someone read over this paper and tell me how it reads so far a.pdf
Could someone read over this paper and tell me how it reads so far a.pdf
ssuserc77a341
 
Find the unit vector that has the same direction as the vector v. v .pdf
Find the unit vector that has the same direction as the vector v.  v .pdfFind the unit vector that has the same direction as the vector v.  v .pdf
Find the unit vector that has the same direction as the vector v. v .pdf
ssuserc77a341
 
1-In order to determine how Haverford Township voters will vote on a.pdf
1-In order to determine how Haverford Township voters will vote on a.pdf1-In order to determine how Haverford Township voters will vote on a.pdf
1-In order to determine how Haverford Township voters will vote on a.pdf
ssuserc77a341
 
Explain how the atmosphere in the Cretaceous may have influenced the.pdf
Explain how the atmosphere in the Cretaceous may have influenced the.pdfExplain how the atmosphere in the Cretaceous may have influenced the.pdf
Explain how the atmosphere in the Cretaceous may have influenced the.pdf
ssuserc77a341
 
Explain the relationships among audit services, attestation services.pdf
Explain the relationships among audit services, attestation services.pdfExplain the relationships among audit services, attestation services.pdf
Explain the relationships among audit services, attestation services.pdf
ssuserc77a341
 
Eric gets twice as much pocket money per week as Frank and Frank get.pdf
Eric gets twice as much pocket money per week as Frank and Frank get.pdfEric gets twice as much pocket money per week as Frank and Frank get.pdf
Eric gets twice as much pocket money per week as Frank and Frank get.pdf
ssuserc77a341
 
During osmosis, individual molecules move Toward lower concentratio.pdf
During osmosis, individual molecules move  Toward lower concentratio.pdfDuring osmosis, individual molecules move  Toward lower concentratio.pdf
During osmosis, individual molecules move Toward lower concentratio.pdf
ssuserc77a341
 
Disorders that result from excessive or inadequate production of hor.pdf
Disorders that result from excessive or inadequate production of hor.pdfDisorders that result from excessive or inadequate production of hor.pdf
Disorders that result from excessive or inadequate production of hor.pdf
ssuserc77a341
 
A sequare region is changed into a rectangular one by making it 2 fe.pdf
A sequare region is changed into a rectangular one by making it 2 fe.pdfA sequare region is changed into a rectangular one by making it 2 fe.pdf
A sequare region is changed into a rectangular one by making it 2 fe.pdf
ssuserc77a341
 
(Unordered Sets) As explained in this chapter, a set is a collection.pdf
(Unordered Sets) As explained in this chapter, a set is a collection.pdf(Unordered Sets) As explained in this chapter, a set is a collection.pdf
(Unordered Sets) As explained in this chapter, a set is a collection.pdf
ssuserc77a341
 

More from ssuserc77a341 (15)

A T1 uses which of the following to multiplex DS0s into a composite .pdf
A T1 uses which of the following to multiplex DS0s into a composite .pdfA T1 uses which of the following to multiplex DS0s into a composite .pdf
A T1 uses which of the following to multiplex DS0s into a composite .pdf
 
Can you solve this question please!! 7. The proportion of the solar .pdf
Can you solve this question please!! 7. The proportion of the solar .pdfCan you solve this question please!! 7. The proportion of the solar .pdf
Can you solve this question please!! 7. The proportion of the solar .pdf
 
CAN and TTP are the two wired network protocols used for distributed .pdf
CAN and TTP are the two wired network protocols used for distributed .pdfCAN and TTP are the two wired network protocols used for distributed .pdf
CAN and TTP are the two wired network protocols used for distributed .pdf
 
34. Cam is a mechanical device that transforms rotary motion into lin.pdf
34. Cam is a mechanical device that transforms rotary motion into lin.pdf34. Cam is a mechanical device that transforms rotary motion into lin.pdf
34. Cam is a mechanical device that transforms rotary motion into lin.pdf
 
1. What is the role of mediator Is it in prokaryotes or eukaryotes..pdf
1. What is the role of mediator Is it in prokaryotes or eukaryotes..pdf1. What is the role of mediator Is it in prokaryotes or eukaryotes..pdf
1. What is the role of mediator Is it in prokaryotes or eukaryotes..pdf
 
Could someone read over this paper and tell me how it reads so far a.pdf
Could someone read over this paper and tell me how it reads so far a.pdfCould someone read over this paper and tell me how it reads so far a.pdf
Could someone read over this paper and tell me how it reads so far a.pdf
 
Find the unit vector that has the same direction as the vector v. v .pdf
Find the unit vector that has the same direction as the vector v.  v .pdfFind the unit vector that has the same direction as the vector v.  v .pdf
Find the unit vector that has the same direction as the vector v. v .pdf
 
1-In order to determine how Haverford Township voters will vote on a.pdf
1-In order to determine how Haverford Township voters will vote on a.pdf1-In order to determine how Haverford Township voters will vote on a.pdf
1-In order to determine how Haverford Township voters will vote on a.pdf
 
Explain how the atmosphere in the Cretaceous may have influenced the.pdf
Explain how the atmosphere in the Cretaceous may have influenced the.pdfExplain how the atmosphere in the Cretaceous may have influenced the.pdf
Explain how the atmosphere in the Cretaceous may have influenced the.pdf
 
Explain the relationships among audit services, attestation services.pdf
Explain the relationships among audit services, attestation services.pdfExplain the relationships among audit services, attestation services.pdf
Explain the relationships among audit services, attestation services.pdf
 
Eric gets twice as much pocket money per week as Frank and Frank get.pdf
Eric gets twice as much pocket money per week as Frank and Frank get.pdfEric gets twice as much pocket money per week as Frank and Frank get.pdf
Eric gets twice as much pocket money per week as Frank and Frank get.pdf
 
During osmosis, individual molecules move Toward lower concentratio.pdf
During osmosis, individual molecules move  Toward lower concentratio.pdfDuring osmosis, individual molecules move  Toward lower concentratio.pdf
During osmosis, individual molecules move Toward lower concentratio.pdf
 
Disorders that result from excessive or inadequate production of hor.pdf
Disorders that result from excessive or inadequate production of hor.pdfDisorders that result from excessive or inadequate production of hor.pdf
Disorders that result from excessive or inadequate production of hor.pdf
 
A sequare region is changed into a rectangular one by making it 2 fe.pdf
A sequare region is changed into a rectangular one by making it 2 fe.pdfA sequare region is changed into a rectangular one by making it 2 fe.pdf
A sequare region is changed into a rectangular one by making it 2 fe.pdf
 
(Unordered Sets) As explained in this chapter, a set is a collection.pdf
(Unordered Sets) As explained in this chapter, a set is a collection.pdf(Unordered Sets) As explained in this chapter, a set is a collection.pdf
(Unordered Sets) As explained in this chapter, a set is a collection.pdf
 

Recently uploaded

Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 

Recently uploaded (20)

Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 

C# 6Write a program that creates a Calculation ClassUse the foll.pdf

  • 1. C# 6 Write a program that creates a Calculation Class Use the following Code and Implement as a class. using System.IO; using System; class Program { static void Main() { int first, second; Console.WriteLine("Enter first number: "); first=Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter second number: "); second=Convert.ToInt32(Console.ReadLine()); int sum = add(first, second); Console.WriteLine("The sum is "+sum); } static int add(int a, int b){ int sum = 0; sum = a + b; return sum; } } The class will have properties for the two numbers the user inputs The class will have methods to: Prompt the user to input two numbers Output results YOU WILL NEED TO IMPLEMENT ERROR HANDLING IN CASE OF BAD INPUT! Solution # include using namespace std; int main() { char o; float num1,num2; cout << "Enter operator either + or - or * or /: "; cin >> o; cout << "Enter two operands: "; cin >> num1 >> num2; switch(o) { case '+': cout << num1+num2; break;
  • 2. case '-': cout << num1-num2; break; case '*': cout << num1*num2; break; case '/': cout << num1/num2; break; default: /* If operator is other than +, -, * or /, error message is shown */ cout << "Error! operator is not correct"; break; } return 0; }