SlideShare a Scribd company logo
1 of 2
Download to read offline
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.pptxKimVeeL
 
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 .pdfmayorothenguyenhob69
 
Seminar 2 coding_principles
Seminar 2 coding_principlesSeminar 2 coding_principles
Seminar 2 coding_principlesmoduledesign
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cppNilesh 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 .pdfanupamfootwear
 
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 2Kaela 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 eteachingeteaching
 
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 IAbdul Rahman Sherzad
 
python lab programs.pdf
python lab programs.pdfpython lab programs.pdf
python lab programs.pdfCBJWorld
 

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 .pdfssuserc77a341
 
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 .pdfssuserc77a341
 
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 .pdfssuserc77a341
 
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.pdfssuserc77a341
 
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..pdfssuserc77a341
 
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.pdfssuserc77a341
 
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 .pdfssuserc77a341
 
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.pdfssuserc77a341
 
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.pdfssuserc77a341
 
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.pdfssuserc77a341
 
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.pdfssuserc77a341
 
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.pdfssuserc77a341
 
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.pdfssuserc77a341
 
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.pdfssuserc77a341
 
(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.pdfssuserc77a341
 

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

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 

Recently uploaded (20)

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........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; }