SlideShare a Scribd company logo
1 of 10
Download to read offline
SJEM2231 STRUCTURED PROGRAMMING 
NAME : WAN MOHAMAD FARHAN BIN AB RAHMAN 
TUTORIAL 1/ LAB 1 (22nd SEPTEMBER 2014) 
QUESTION 1 
Write a program to print the word “Welcome”. 
#include <iostream> 
using namespace std; 
int main() 
{ 
cout << "Welcome n"; 
return 0; 
} 
//Output : 
Welcome 
QUESTION 2 
Write a program to print a sentence in a single line and in three lines as like below. 
Hello, welcome to C++ Programming and 
Hello, 
welcome to 
C++ Programming
#include <iostream> 
using namespace std; 
int main() 
{ 
cout << "Hello, welcome to C++ Programming n" ; 
return 0; 
} 
//Output : 
Hello, welcome to C++ Programming 
#include <iostream> 
using namespace std; 
int main() 
{ 
cout << "Hello,n welcome ton C++ Programmingn"; 
return 0; 
} 
//Output : 
Hello, 
welcome to 
C++ programming
QUESTION 3 
Write a program that prints the sum, difference and product of two integers. Initialize the integers with the values 14 and 8. 
#include <iostream> 
using namespace std; 
int main() 
{ 
int a,b ; 
int sum, difference, product; 
a=14; 
b=8; 
sum= a+b; 
difference= a-b; 
product= a*b; 
cout << sum <<"n"; 
cout << difference <<"n"; 
cout << product <<"n”; 
return 0; 
} 
// Output: 
22 
6 
112
QUESTION 4 
Write a program that prints the sum, difference, product, quotient, and remainder of two numbers that are input interactively. 
#include <iostream> 
using namespace std; 
int main() 
{ 
int a,b; 
int sum, diff, product, quotient, remainder; 
cout << "Please enter a value of a: " ; 
cin >> a; 
cout << "Please enter a value of b: " ; 
cin >> b; 
sum=a+b; 
diff=a-b; 
product=a*b; 
quotient=a / b; 
remainder = a%b; 
cout << “The sum of a and b is : “ << sum <<"n"; 
cout << “The difference of a and b is : “ << diff <<"n"; 
cout << “The product of a and b is : “ << product <<"n"; 
cout << “The quotient of a and b is : “ << quotient<<"n"; 
cout << “The remainder of a and b is : “<< remainder<<"n";
return 0; 
} 
//Output : 
Please enter a value of a: 34 
Please enter a value of b: 27 
The sum of a and b is : 61 
The difference of a and b is : 7 
The product of a and b is : 918 
The quotient of a and b is : 1 
The remainder of a and b is : 7 
QUESTION 5 
Write a program to read the floating point number and convert it to integer 
//Using truncate method 
#include <iostream> 
using namespace std; 
int main() 
{ 
float x; 
int y; 
cout<<"Please enter a decimal number : "; 
cin >> x; 
y=x; 
cout<<"The integer number you will get is : "<< y << endl; 
return 0; 
}
//Output_truncate : 
Please enter a decimal number : 45.77 
The integer number you will get is : 45 
//Using round off method directly : 
#include <iostream> 
#include <cmath> 
using namespace std; 
double round(double value) 
{ 
return(floor(value+0.5)); 
} 
int main() 
{ 
double x,value; 
int y; 
write: 
cout <<"Please enter a decimal number : "; 
cin >>x; 
y = round(x); 
cout<<"The integer number that you will get after round off is : "<< y<<endl; 
cout<<"Do you want to continue with other decimal number? n"; 
cout<<"Press 1 for Yes ornPress 2 for Nonn"; 
cin>> value; 
if(value==1)
{ 
goto write; 
} 
else if(value==2) 
{ 
return 0; 
} 
else 
{ 
cout<<"Error! Please understand the COMMAND!!" <<endl; 
goto write; 
} 
} 
//Output_roundoff to integer directly 
Please enter a decimal number : 56.44 
The integer number that you will get after round off is : 56 
Do you want to continue with other decimal number? 
Press 1 for Yes or 
Press 2 for No 
1 
Please enter a decimal number : 1000.87 
The integer number that you will get after round off is : 1001 
Do you want to continue with other decimal number?
Press 1 for Yes or 
Press 2 for No 
8 
Error! Please understand the COMMAND!! 
Please enter a decimal number : 194.499 
The integer number that you will get after round off is : 194 
Do you want to continue with other decimal number? 
Press 1 for Yes or 
Press 2 for No 
2 
Press any key to continue 
//Round off method by using setprecision() to set the decimal places : 
#include <iostream> 
#include <cmath> //nothing happened if we eliminate this cmath 
#include <iomanip> // Input output manipulator, use setprecision() 
using namespace std; 
int main() 
{ 
long double x,value; 
int y;
write: 
cout << "Please enter a decimal number : "; 
cin >>x; 
y = long double (x); 
cout<< "The integer number you will get is : "; 
cout<< fixed << setprecision (0) << x <<endl; 
/* fixed is used before setprecision() to ensure that when we set the setprecision(0), it will round off to integer, if we make setprecision(1), setprecision(2), etc ; it will round off to 1 decimal place ,2 decimal places and so on respectively */ 
cout<< "Do you want to continue with other decimal number?n"; 
cout<<"Press 1 for Yes ornPress 2 for Nonn"; 
cin>> value; 
if(value==1) 
{ 
goto write; // goto (statement); 
} 
else if(value==2) 
{ 
return 0; 
} 
else 
{ 
cout<< "Error! Please understand the COMMAND!!" <<endl; 
goto write; 
} 
}
//Output_round off method using setprecision() 
Please enter a decimal number : 454535.435 
The integer number you will get is : 454535 
Do you want to continue with other decimal number? 
Press 1 for Yes or 
Press 2 for No 
1 
Please enter a decimal number : 44.78 
The integer number you will get is : 45 
Do you want to continue with other decimal number? 
Press 1 for Yes or 
Press 2 for No 
1 
Please enter a decimal number : 0.999993 
The integer number you will get is : 1 
Do you want to continue with other decimal number? 
Press 1 for Yes or 
Press 2 for No 
2

More Related Content

What's hot

Programa en C++ ( escriba 3 números y diga cual es el mayor))
Programa en C++ ( escriba 3 números y diga cual es el mayor))Programa en C++ ( escriba 3 números y diga cual es el mayor))
Programa en C++ ( escriba 3 números y diga cual es el mayor))
Alex Penso Romero
 

What's hot (20)

C++ TUTORIAL 2
C++ TUTORIAL 2C++ TUTORIAL 2
C++ TUTORIAL 2
 
New presentation oop
New presentation oopNew presentation oop
New presentation oop
 
C++ file
C++ fileC++ file
C++ file
 
Basic Programs of C++
Basic Programs of C++Basic Programs of C++
Basic Programs of C++
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101
 
Container adapters
Container adaptersContainer adapters
Container adapters
 
Oop1
Oop1Oop1
Oop1
 
C sharp 8
C sharp 8C sharp 8
C sharp 8
 
Stl algorithm-Basic types
Stl algorithm-Basic typesStl algorithm-Basic types
Stl algorithm-Basic types
 
Static and const members
Static and const membersStatic and const members
Static and const members
 
Programa en C++ ( escriba 3 números y diga cual es el mayor))
Programa en C++ ( escriba 3 números y diga cual es el mayor))Programa en C++ ( escriba 3 números y diga cual es el mayor))
Programa en C++ ( escriba 3 números y diga cual es el mayor))
 
C++ Programming - 4th Study
C++ Programming - 4th StudyC++ Programming - 4th Study
C++ Programming - 4th Study
 
C++ programs
C++ programsC++ programs
C++ programs
 
Implementing stack
Implementing stackImplementing stack
Implementing stack
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Opp compile
Opp compileOpp compile
Opp compile
 
C++ Programming - 1st Study
C++ Programming - 1st StudyC++ Programming - 1st Study
C++ Programming - 1st Study
 
C++ Programming - 2nd Study
C++ Programming - 2nd StudyC++ Programming - 2nd Study
C++ Programming - 2nd Study
 
C++ Programming - 14th Study
C++ Programming - 14th StudyC++ Programming - 14th Study
C++ Programming - 14th Study
 

Viewers also liked

Computer Math Day 03 Addition
Computer Math Day 03 AdditionComputer Math Day 03 Addition
Computer Math Day 03 Addition
A Jorge Garcia
 
Database Q&A
Database  Q&ADatabase  Q&A
Database Q&A
eduafo
 
FINAL PAPER FP304 DATABASE SYSTEM
FINAL PAPER FP304 DATABASE SYSTEMFINAL PAPER FP304 DATABASE SYSTEM
FINAL PAPER FP304 DATABASE SYSTEM
Amira Dolce Farhana
 
Database Management System And Design Questions
Database Management System And Design QuestionsDatabase Management System And Design Questions
Database Management System And Design Questions
Samir Sabry
 
2009 Punjab Technical University B.C.A Database Management System Question paper
2009 Punjab Technical University B.C.A Database Management System Question paper2009 Punjab Technical University B.C.A Database Management System Question paper
2009 Punjab Technical University B.C.A Database Management System Question paper
Monica Sabharwal
 
5 structured programming
5 structured programming 5 structured programming
5 structured programming
hccit
 
Previous question papers of Database Management System (DBMS) By SHABEEB
Previous question papers of Database Management System (DBMS) By SHABEEBPrevious question papers of Database Management System (DBMS) By SHABEEB
Previous question papers of Database Management System (DBMS) By SHABEEB
Shabeeb Shabi
 
Computers as information and communication technology
Computers as information and communication technologyComputers as information and communication technology
Computers as information and communication technology
Junarie Ramirez
 
LA5_Generation of Programming Languages
LA5_Generation of Programming LanguagesLA5_Generation of Programming Languages
LA5_Generation of Programming Languages
Cma Mohd
 

Viewers also liked (20)

Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
Computer Math Day 03 Addition
Computer Math Day 03 AdditionComputer Math Day 03 Addition
Computer Math Day 03 Addition
 
Computer Based Math
Computer Based MathComputer Based Math
Computer Based Math
 
Computer math
Computer mathComputer math
Computer math
 
[SpLab3]Structures
[SpLab3]Structures[SpLab3]Structures
[SpLab3]Structures
 
Database Q&A
Database  Q&ADatabase  Q&A
Database Q&A
 
Fskik 1 nota
Fskik 1   notaFskik 1   nota
Fskik 1 nota
 
FINAL PAPER FP304 DATABASE SYSTEM
FINAL PAPER FP304 DATABASE SYSTEMFINAL PAPER FP304 DATABASE SYSTEM
FINAL PAPER FP304 DATABASE SYSTEM
 
Bcsl 031 solve assignment
Bcsl 031 solve assignmentBcsl 031 solve assignment
Bcsl 031 solve assignment
 
Database Management System And Design Questions
Database Management System And Design QuestionsDatabase Management System And Design Questions
Database Management System And Design Questions
 
2009 Punjab Technical University B.C.A Database Management System Question paper
2009 Punjab Technical University B.C.A Database Management System Question paper2009 Punjab Technical University B.C.A Database Management System Question paper
2009 Punjab Technical University B.C.A Database Management System Question paper
 
Dbms Final Examination Answer Key
Dbms Final Examination Answer KeyDbms Final Examination Answer Key
Dbms Final Examination Answer Key
 
Mcs 16 solved assignment 2015-16
Mcs 16 solved assignment 2015-16Mcs 16 solved assignment 2015-16
Mcs 16 solved assignment 2015-16
 
Ada 95 - Structured programming
Ada 95 - Structured programmingAda 95 - Structured programming
Ada 95 - Structured programming
 
Fundamentals of Database Systems Questions and Answers
Fundamentals of Database Systems Questions and AnswersFundamentals of Database Systems Questions and Answers
Fundamentals of Database Systems Questions and Answers
 
Objective structured practical question
Objective structured practical questionObjective structured practical question
Objective structured practical question
 
5 structured programming
5 structured programming 5 structured programming
5 structured programming
 
Previous question papers of Database Management System (DBMS) By SHABEEB
Previous question papers of Database Management System (DBMS) By SHABEEBPrevious question papers of Database Management System (DBMS) By SHABEEB
Previous question papers of Database Management System (DBMS) By SHABEEB
 
Computers as information and communication technology
Computers as information and communication technologyComputers as information and communication technology
Computers as information and communication technology
 
LA5_Generation of Programming Languages
LA5_Generation of Programming LanguagesLA5_Generation of Programming Languages
LA5_Generation of Programming Languages
 

Similar to C++ TUTORIAL 1

Assignement of programming & problem solving
Assignement of programming & problem solvingAssignement of programming & problem solving
Assignement of programming & problem solving
Syed Umair
 
Rajeev oops 2nd march
Rajeev oops 2nd marchRajeev oops 2nd march
Rajeev oops 2nd march
Rajeev Sharan
 

Similar to C++ TUTORIAL 1 (20)

C101-PracticeProblems.pdf
C101-PracticeProblems.pdfC101-PracticeProblems.pdf
C101-PracticeProblems.pdf
 
Practiceproblems(1)
Practiceproblems(1)Practiceproblems(1)
Practiceproblems(1)
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
 
Solved Practice Problems For the C++ Exams
Solved Practice Problems For the C++ ExamsSolved Practice Problems For the C++ Exams
Solved Practice Problems For the C++ Exams
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
Project in programming
Project in programmingProject in programming
Project in programming
 
Output in c++ (cout)
Output in c++ (cout)Output in c++ (cout)
Output in c++ (cout)
 
Practical basics on c++
Practical basics on c++Practical basics on c++
Practical basics on c++
 
Assignement of programming & problem solving
Assignement of programming & problem solvingAssignement of programming & problem solving
Assignement of programming & problem solving
 
Ch4
Ch4Ch4
Ch4
 
C++ L03-Control Structure
C++ L03-Control StructureC++ L03-Control Structure
C++ L03-Control Structure
 
C++ loop
C++ loop C++ loop
C++ loop
 
Rajeev oops 2nd march
Rajeev oops 2nd marchRajeev oops 2nd march
Rajeev oops 2nd march
 
Statement
StatementStatement
Statement
 
Cpp c++ 1
Cpp c++ 1Cpp c++ 1
Cpp c++ 1
 
C++basics
C++basicsC++basics
C++basics
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
 
EJERCICIOS DE BORLAND C++ 2DA PARTE.docx
EJERCICIOS DE BORLAND C++ 2DA PARTE.docxEJERCICIOS DE BORLAND C++ 2DA PARTE.docx
EJERCICIOS DE BORLAND C++ 2DA PARTE.docx
 
EJERCICIOS DE BORLAND C++ 2DA PARTE.docx
EJERCICIOS DE BORLAND C++ 2DA PARTE.docxEJERCICIOS DE BORLAND C++ 2DA PARTE.docx
EJERCICIOS DE BORLAND C++ 2DA PARTE.docx
 
c++basics.ppt
c++basics.pptc++basics.ppt
c++basics.ppt
 

Recently uploaded

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Recently uploaded (20)

Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 

C++ TUTORIAL 1

  • 1. SJEM2231 STRUCTURED PROGRAMMING NAME : WAN MOHAMAD FARHAN BIN AB RAHMAN TUTORIAL 1/ LAB 1 (22nd SEPTEMBER 2014) QUESTION 1 Write a program to print the word “Welcome”. #include <iostream> using namespace std; int main() { cout << "Welcome n"; return 0; } //Output : Welcome QUESTION 2 Write a program to print a sentence in a single line and in three lines as like below. Hello, welcome to C++ Programming and Hello, welcome to C++ Programming
  • 2. #include <iostream> using namespace std; int main() { cout << "Hello, welcome to C++ Programming n" ; return 0; } //Output : Hello, welcome to C++ Programming #include <iostream> using namespace std; int main() { cout << "Hello,n welcome ton C++ Programmingn"; return 0; } //Output : Hello, welcome to C++ programming
  • 3. QUESTION 3 Write a program that prints the sum, difference and product of two integers. Initialize the integers with the values 14 and 8. #include <iostream> using namespace std; int main() { int a,b ; int sum, difference, product; a=14; b=8; sum= a+b; difference= a-b; product= a*b; cout << sum <<"n"; cout << difference <<"n"; cout << product <<"n”; return 0; } // Output: 22 6 112
  • 4. QUESTION 4 Write a program that prints the sum, difference, product, quotient, and remainder of two numbers that are input interactively. #include <iostream> using namespace std; int main() { int a,b; int sum, diff, product, quotient, remainder; cout << "Please enter a value of a: " ; cin >> a; cout << "Please enter a value of b: " ; cin >> b; sum=a+b; diff=a-b; product=a*b; quotient=a / b; remainder = a%b; cout << “The sum of a and b is : “ << sum <<"n"; cout << “The difference of a and b is : “ << diff <<"n"; cout << “The product of a and b is : “ << product <<"n"; cout << “The quotient of a and b is : “ << quotient<<"n"; cout << “The remainder of a and b is : “<< remainder<<"n";
  • 5. return 0; } //Output : Please enter a value of a: 34 Please enter a value of b: 27 The sum of a and b is : 61 The difference of a and b is : 7 The product of a and b is : 918 The quotient of a and b is : 1 The remainder of a and b is : 7 QUESTION 5 Write a program to read the floating point number and convert it to integer //Using truncate method #include <iostream> using namespace std; int main() { float x; int y; cout<<"Please enter a decimal number : "; cin >> x; y=x; cout<<"The integer number you will get is : "<< y << endl; return 0; }
  • 6. //Output_truncate : Please enter a decimal number : 45.77 The integer number you will get is : 45 //Using round off method directly : #include <iostream> #include <cmath> using namespace std; double round(double value) { return(floor(value+0.5)); } int main() { double x,value; int y; write: cout <<"Please enter a decimal number : "; cin >>x; y = round(x); cout<<"The integer number that you will get after round off is : "<< y<<endl; cout<<"Do you want to continue with other decimal number? n"; cout<<"Press 1 for Yes ornPress 2 for Nonn"; cin>> value; if(value==1)
  • 7. { goto write; } else if(value==2) { return 0; } else { cout<<"Error! Please understand the COMMAND!!" <<endl; goto write; } } //Output_roundoff to integer directly Please enter a decimal number : 56.44 The integer number that you will get after round off is : 56 Do you want to continue with other decimal number? Press 1 for Yes or Press 2 for No 1 Please enter a decimal number : 1000.87 The integer number that you will get after round off is : 1001 Do you want to continue with other decimal number?
  • 8. Press 1 for Yes or Press 2 for No 8 Error! Please understand the COMMAND!! Please enter a decimal number : 194.499 The integer number that you will get after round off is : 194 Do you want to continue with other decimal number? Press 1 for Yes or Press 2 for No 2 Press any key to continue //Round off method by using setprecision() to set the decimal places : #include <iostream> #include <cmath> //nothing happened if we eliminate this cmath #include <iomanip> // Input output manipulator, use setprecision() using namespace std; int main() { long double x,value; int y;
  • 9. write: cout << "Please enter a decimal number : "; cin >>x; y = long double (x); cout<< "The integer number you will get is : "; cout<< fixed << setprecision (0) << x <<endl; /* fixed is used before setprecision() to ensure that when we set the setprecision(0), it will round off to integer, if we make setprecision(1), setprecision(2), etc ; it will round off to 1 decimal place ,2 decimal places and so on respectively */ cout<< "Do you want to continue with other decimal number?n"; cout<<"Press 1 for Yes ornPress 2 for Nonn"; cin>> value; if(value==1) { goto write; // goto (statement); } else if(value==2) { return 0; } else { cout<< "Error! Please understand the COMMAND!!" <<endl; goto write; } }
  • 10. //Output_round off method using setprecision() Please enter a decimal number : 454535.435 The integer number you will get is : 454535 Do you want to continue with other decimal number? Press 1 for Yes or Press 2 for No 1 Please enter a decimal number : 44.78 The integer number you will get is : 45 Do you want to continue with other decimal number? Press 1 for Yes or Press 2 for No 1 Please enter a decimal number : 0.999993 The integer number you will get is : 1 Do you want to continue with other decimal number? Press 1 for Yes or Press 2 for No 2