SlideShare uma empresa Scribd logo
1 de 10
Baixar para ler 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

Mais conteúdo relacionado

Mais procurados

Basic Programs of C++
Basic Programs of C++Basic Programs of C++
Basic Programs of C++Bharat Kalia
 
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-ee01083101premrings
 
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
 
C++ Programming - 4th Study
C++ Programming - 4th StudyC++ Programming - 4th Study
C++ Programming - 4th StudyChris Ohk
 
C++ Programming - 1st Study
C++ Programming - 1st StudyC++ Programming - 1st Study
C++ Programming - 1st StudyChris Ohk
 
C++ Programming - 2nd Study
C++ Programming - 2nd StudyC++ Programming - 2nd Study
C++ Programming - 2nd StudyChris Ohk
 
C++ Programming - 14th Study
C++ Programming - 14th StudyC++ Programming - 14th Study
C++ Programming - 14th StudyChris Ohk
 

Mais procurados (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
 

Destaque

Computer Math Day 03 Addition
Computer Math Day 03 AdditionComputer Math Day 03 Addition
Computer Math Day 03 AdditionA Jorge Garcia
 
Computer Based Math
Computer Based MathComputer Based Math
Computer Based Mathdwees
 
Computer math
Computer mathComputer math
Computer mathPDE1D
 
[SpLab3]Structures
[SpLab3]Structures[SpLab3]Structures
[SpLab3]StructuresNora Youssef
 
Database Q&A
Database  Q&ADatabase  Q&A
Database Q&Aeduafo
 
FINAL PAPER FP304 DATABASE SYSTEM
FINAL PAPER FP304 DATABASE SYSTEMFINAL PAPER FP304 DATABASE SYSTEM
FINAL PAPER FP304 DATABASE SYSTEMAmira Dolce Farhana
 
Database Management System And Design Questions
Database Management System And Design QuestionsDatabase Management System And Design Questions
Database Management System And Design QuestionsSamir 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 paperMonica Sabharwal
 
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 AnswersAbdul Rahman Sherzad
 
Objective structured practical question
Objective structured practical questionObjective structured practical question
Objective structured practical questionAnisur Rahman
 
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 SHABEEBShabeeb Shabi
 
Computers as information and communication technology
Computers as information and communication technologyComputers as information and communication technology
Computers as information and communication technologyJunarie Ramirez
 
LA5_Generation of Programming Languages
LA5_Generation of Programming LanguagesLA5_Generation of Programming Languages
LA5_Generation of Programming LanguagesCma Mohd
 

Destaque (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
 

Semelhante a C++ TUTORIAL 1

C101-PracticeProblems.pdf
C101-PracticeProblems.pdfC101-PracticeProblems.pdf
C101-PracticeProblems.pdfT17Rockstar
 
Practiceproblems(1)
Practiceproblems(1)Practiceproblems(1)
Practiceproblems(1)Sena Nama
 
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 JobyGrejoJoby1
 
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++ ExamsMuhammadTalha436
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAAiman Hud
 
Output in c++ (cout)
Output in c++ (cout)Output in c++ (cout)
Output in c++ (cout)Ghada Shebl
 
Practical basics on c++
Practical basics on c++Practical basics on c++
Practical basics on c++Marco Izzotti
 
Assignement of programming & problem solving
Assignement of programming & problem solvingAssignement of programming & problem solving
Assignement of programming & problem solvingSyed Umair
 
C++ L03-Control Structure
C++ L03-Control StructureC++ L03-Control Structure
C++ L03-Control StructureMohammad Shaker
 
Rajeev oops 2nd march
Rajeev oops 2nd marchRajeev oops 2nd march
Rajeev oops 2nd marchRajeev Sharan
 
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 overloadingkinan keshkeh
 
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.docxleovasquez17
 
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.docxleovasquez17
 

Semelhante a 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
 

Último

Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
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 FellowsMebane Rash
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
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.pdfAdmir Softic
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 

Último (20)

Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
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
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
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
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 

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