ebook img

Computer science to the Point. Computer Science for Life Sciences Students and Other Non-Computer Scientists PDF

328 Pages·2023·8.897 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Computer science to the Point. Computer Science for Life Sciences Students and Other Non-Computer Scientists

Boris Tolg Computer science to the Point Computer Science for Life Sciences Students and Other Non-Computer Scientists Computer science to the Point Boris Tolg Computer science to the Point Computer Science for Life Sciences Students and Other Non-Computer Scientists Boris Tolg Department Medizintechnik HAW Hamburg Fakultät Life Sciences Hamburg, Germany ISBN 978-3-658-38442-5 ISBN 978-3-658-38443-2 (eBook) https://doi.org/10.1007/978-3-658-38443-2 © The Editor(s) (if applicable) and The Author(s), under exclusive licence to Springer Fachmedien Wiesbaden GmbH, part of Springer Nature 2019, 2023 This book is a translation of the original German edition “Informatik auf den Punkt gebracht” by Tolg, Boris, published by Springer Fachmedien Wiesbaden GmbH in 2019. The translation was done with the help of artifi- cial intelligence (machine translation by the service DeepL.com). A subsequent human revision was done pri- marily in terms of content, so that the book will read stylistically differently from a conventional translation. Springer Nature works continuously to further the development of tools for the production of books and on the related technologies to support the authors. This work is subject to copyright. All rights are solely and exclusively licensed by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or informa- tion storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. The use of general descriptive names, registered names, trademarks, service marks, etc. in this publication does not imply, even in the absence of a specific statement, that such names are exempt from the relevant protective laws and regulations and therefore free for general use. The publisher, the authors, and the editors are safe to assume that the advice and information in this book are believed to be true and accurate at the date of publication. Neither the publisher nor the authors or the editors give a warranty, expressed or implied, with respect to the material contained herein or for any errors or omissions that may have been made. The publisher remains neutral with regard to jurisdictional claims in published maps and institutional affiliations. This Springer imprint is published by the registered company Springer Fachmedien Wiesbaden GmbH, part of Springer Nature. The registered company address is: Abraham-Lincoln-Str. 46, 65189 Wiesbaden, Germany For my wife Christine and my sons Jean Luc and Mateo Nicolao. Preface The idea for the Life Sciences book series came about in December 2015, when I was in the process of developing new teaching concepts for my computer science lecture. While searching for suitable literature, I noticed that although there is a wide range of books, workshops, and online tutorials for the C++ programming language on the market, none of them meet the needs of my students. Each of the offerings in itself, of course, serves its purpose and is sometimes more and sometimes less successful, but all of them assume that readers have an intrinsic motivation to become involved in computer science. However, this motivation cannot necessarily be assumed for students who take com- puter science as a minor in an interdisciplinary degree program. As diverse as the compo- sition of subjects in an interdisciplinary degree program is, so diverse are the careers of students who have completed these programs. Not all of them focus on software develop- ment, and some will probably never write another program after graduation. In these courses, it is important to provide students with a different motivation as to why they should pursue computer science. However, this problem does not only affect computer science, but all basic subjects of an interdisciplinary course of studies. Consequently, it makes sense to build up a common teaching concept that extends across different basic subjects. The idea is to define tasks that originate from the respective courses of study and then to break them down into prob- lems of the basic subjects. In this way, the individual books can function on their own as textbooks for their field of application, but in interaction with the other volumes they can offer a self-contained description of solutions for subject-specific problems. You, the reader of these lines, thus have the possibility to concentrate only on the works that are really interesting for you. The subject-specific problems provide motivation to deal with the respective basic subject. I am very happy that I was able to win over a number of colleagues to help me realize my idea. Thus, in addition to the book on computer science, other books are appearing with the subjects of physics and mathematics. The future will show whether the list will become even longer. vii viii Preface Of course, I would be very pleased if the teaching concept of the books would simplify your entry into the basic subjects. Therefore, I wish you much fun and success in reading the book and learning the basics of computer science. I have tried to adapt the book to the best of my knowledge and belief to the needs of students in the minor subject. I would like to express my sincere thanks to two of my stu- dents, Ms. Lea Jungnickel and Ms. Sandra Kerstin Spangenberg, who read the book from a student’s perspective and pointed out the incomprehensible passages to me. Prof. Dr. Holger Kohlhoff and Prof. Dr. Jürgen Lorenz supported me in terms of content during the troubleshooting. I would also like to thank them from the bottom of my heart. Reinbek Boris Tolg August 2018 Contents Part I Introduction 1 How to Work with This Book 3 2 Documentation of Languages and Programs 5 2.1 Syntax Diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.2 Unified Modelling Language (UML) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 2.2.1 The Use Case Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 2.2.2 The Activity Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 2.2.3 The Class Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 3 Taxonomy Levels 23 Part II Basics 4 The Language 29 4.1 The First Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 4.2 A Few More Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 5 Variables 35 5.1 Variable Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 5.2 Type Conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 5.3 Enumerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 5.4 Advanced: const, external and static . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 5.4.1 const . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 5.4.2 external . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 5.4.3 static . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 5.5 Advanced: An Introduction to Number Systems . . . . . . . . . . . . . . . . . . . . . 44 5.5.1 Addition and Multiplication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 5.5.2 Subtraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 5.5.3 Hexadecimal Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 ix x Contents 6 Branches 55 6.1 Operators for Comparisons and Logical Operations . . . . . . . . . . . . . . . . . . 55 6.2 if-statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 6.3 switch-case statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 7 Loops 67 7.1 do-while loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 7.2 while-loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 7.3 for-loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 7.4 continue and break . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 8 Arrays 81 8.1 Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 8.2 Multidimensional Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 8.3 Multidimensional Arrays with Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 9 Functions 95 9.1 Overloading Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 9.2 Function Prototypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 9.3 References and Arrays as Function Parameters . . . . . . . . . . . . . . . . . . . . . . 102 9.3.1 Arrays as Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 9.4 Advanced: Pre-assigned Function Parameters . . . . . . . . . . . . . . . . . . . . . . . 106 9.5 Advanced: Variadic Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 9.6 Advanced: Recursive Calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 9.7 Advanced: static . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 10 Classes and Structures 119 10.1 Constructors and Destructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 10.2 Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 10.3 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 10.4 Inheritance and Polymorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 10.5 Advanced: Abstract Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150 10.6 Advanced: Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 10.7 Advanced: const and static . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 10.7.1 c onst . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 10.7.2 s tatic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 11 Pointer 163 11.1 Type Conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 11.2 const . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170 Contents xi 11.3 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 11.4 Pointer Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 11.5 Advanced: Multidimensional Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 11.5.1 Variant 1: Pointer to Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 11.5.2 Variant 2: Pointer to Pointer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 11.5.3 Variant 3: Virtual Dimensions . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 11.6 Advanced: malloc, realloc, free and memcpy . . . . . . . . . . . . . . . . . . . . . . 185 11.7 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189 11.7.1 Call by Pointer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190 11.7.2 Function Pointer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191 11.8 Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194 11.8.1 Polymorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 11.8.2 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200 11.9 Advanced: Unions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209 Part III Problems 12 Electrocardiography 215 12.1 Planning the Software Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216 12.2 Loading the ECG Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 12.2.1 Description of the MIT Format . . . . . . . . . . . . . . . . . . . . . . . . . . 224 12.2.2 Extension of the Software Architecture . . . . . . . . . . . . . . . . . . . . 227 12.2.3 Implementation of the Loading Function . . . . . . . . . . . . . . . . . . 230 12.3 Data Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253 12.3.1 Extension of the Software Architecture . . . . . . . . . . . . . . . . . . . . 255 12.3.2 Implementation of the Fast Fourier Transformation . . . . . . . . . . 257 12.4 Exporting the Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265 12.4.1 Extension of the Software Architecture . . . . . . . . . . . . . . . . . . . . 266 12.4.2 Implementation of the Export Function . . . . . . . . . . . . . . . . . . . . 266 12.4.3 Presentation of the Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272 Solutions 275 References 325

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.