Monograph On C++ Tutorial Problems
Dr. M.A.Jayaram Director Department of Master of Computer Applications Siddaganga Institute of Technology, Tumkur, India
1
A Monograph On C ++ – TUTORIAL PROGRAMS By M.A.Jayaram
A Publication by
Department of Master of Computer Applications
Siddaganga Institute of Technology Tumkur, India. July-2017
2
Preface This monograph is presented with a strong intent to teach or to give an experience on program development in C++ to an undergraduate or a post graduate student. This book presents a collection of C++ programs that are usually attempted by a student who is a beginner or in the lower semesters of an undergraduate or a diploma programme. The programs are drawn from the tutorial sessions and lecture notes of the author. It is presumed that the reader has some previous acquaintance with programming i.e., reader needs to know what a variable is and what a function is -- but doesn’t need much experience. This monograph presents a compendium of workable C++ programs. It is essential to follow the order of the chapters rigorously; if the reader is a beginner to C++. For others, it may be useful as a handbook particularly for tutors. The example programs covered in this book range from simple programs without object oriented tinge to programs that are object oriented with an increasing order of proficiency. Further, the material presented in this monograph is expected to serve as guidelines for writing programs on problems which are not covered in this monograph or for writing programs on engineering domain specific problems. Any suggestions for the improvement of this work are gratefully acknowledged.
Dr.M.A.Jayaram
[email protected] 24.06.2017
3
Contents
1.
Sequential Programs
5
2.
Decision Control Constructs
19
3.
Looping Constructs
27
4.
Programs on Arrays
50
5.
Programs on Strings
79
6.
Programs on Structures and Unions
101
7.
Programs on Pointers
120
8.
File handling
130
9.
Programs based on oop’s concepts.
188
4
Simple Sequential C++ Programs
1. Program to create two sentences on screen #include void main() { // to print a simple message cout>marks_card.comp_prog>>marks _card.maths; // calculating Average marks marks_card.avg_marks = (marks_card.eng_mech + marks_card.comp_prog + marks_card.maths) / 3.0 ; cout=dim2+dim1) { coutgetdimension(); ar=ptr1->area(); cout