1 / 20

 Data structures and algorithms – TP1

This document provides information about the grading criteria for the lab assignments and big homework assignments for the Data Structures and Algorithms TP1 course. It also includes instructions for submitting assignments and a link to check lab grades.

lsessions
Télécharger la présentation

 Data structures and algorithms – TP1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1.  Data structures and algorithms – TP1 mariaiuliana.dascalu@gmail.com www.mariaiulianadascalu.com

  2. Grading • The lab grade represents 50% of the final grade: • 30% - 3 big home assignments(you can workalone or in teams of 2) • 20% - activityduringlabs(presence, activity, smallhomeworks) • Small bonus for exceptionalhomeworks • Important! Attending at least 8 labs (requirement for taking the exam). Otherwise, you will have to redo the lab next year.

  3. Grading and homeworks • The labs and the 3 big assignmentswillbe put onmoodle(LabX_MariaDascalu). • You will use the sameplatform to uploadyourbigassignment solutions (respecting the deadline) and youwill have to presentthemduring the following lab. If you have problemswith the moodleupload, youcanalsosend the homework by email. • Important! The bigassignmentswillbecheckedagainstplagiarism! • You can check yourlab grades at the end of eachweek in this google spreadsheet: https://docs.google.com/spreadsheets/d/1VxKQE8_LbIIPuTqawwhvsHeDjLho9i2mc8t71jLadHI/edit?usp=sharing

  4. Questions • For any question, youcan contact me at the following email address: mariaiuliana.dascalu@gmail.com • You canalso use the forum: (http://fils.curs.pub.ro)

  5. Tools • Recommended: CodeBlocks with the compiler included (codeblocks-17.12mingw-setup.exe): http://www.codeblocks.org/downloads/26 • Other IDE: Visual Studio Community Edition, C-Free 4.0 Standard, NetBeans (with C++ plugin), GCC for Linux • If CodeBlocks fails to detect the C++ compiler by default, you can set its path manually from Settings -> Compiler -> Toolchain executables • When you create a new project in CodeBlocks, the default type for C/C++ projects that you should choose is “Console Application”

  6. Objectives • to run and compile C programs; • to identify the structure of a C program; • to use standard I/O operations; • to define variables; • to declare and implement functions;

  7. Typical C program • A C program is written in a file with the “.c” extension: the source code. • After compilation, another file, with the “.o” extension appears: the object code. • After execution, another file, with the “.exe” extension appears: the executable.

  8. Typical C program • Structure: • Pre-processing directives – tells the compiler to put code from the header into our program before actually creating the executable (eg: stdio.h – C libraryneeded for using printf and scanf) • One or more functions (main is mandatory), with loops, if structures etc. ! Attention, C is case sensitive!

  9. REFERENCES • “C++ ProgrammingLanguage”, Bjarne Stroustroup • “Thinking in C++”, by Bruce Eckel & Chuck Allison • “C++ Plus Data Structures”, by Nell Dale • “Limbajele C si C++ pentruincepatori”(vol 1-C, vol 2-C++), by LiviuNegrescu (romanian) • http://www.cplusplus.com/reference • Tutorials point: http://www.tutorialspoint.com/cprogramming/ • C Programming and C++ Programming: http://www.cprogramming.com/

  10. A. Standard Output Operations

  11. A. Standard Output Operations • Format specifiers: int %iou %d char %c %f float double %lf string %s

  12. Signature of printffunction • printf(control, par1, par2, …, parn); Where • control = a string which defines the texts and the format parameters (between “ “) • par1, par2, …, parn = expressions; their values are written taking into account the format parameters from control Exercise: Test the format specifiers of the printffunction

  13. Exercise: Extract the rules for printfsignature: printf("*%4c**", getchar()); printf("*%-4c**", getchar());

  14. B. Standard Input Operations • «Scanf» has the same signature as «printf»  and isdefined in «stdio.h» .

  15. Ex1. Write a program to calculate  the average between two float numbers. The result shall be displayed with 2 decimals. Use scanf and printf! • %.2f   -> format parameter for float with 2 decimals

  16. Functions: declaration and implementation • Signature: type_of_the_returned_resultfunction_name(list_of_formal_params) { declaration_of_local_variables; instructions; } • Visibility domain: local vs. global variables • Parameter passing: by-value

  17. Exemple functions

  18. Exemple - observations • Note the use of math.h library: for sqrt function (the same meaning as in Java) • Note the control flow structures (if, if-else, for, …) •Note the function definition and call: the implemented function calculates if a number is prime or not

  19. Use functions for solving the followingexercises: • Ex2. Display the minimum of threefloatnumbers, readwithscanf. • Ex3. Write a program whichsums the digits of all numberssituated in a giveninterval. The endpoints of the interval are readfrom keyboard. • Ex4. Write a program whichreads an intnumber and checks if it’s a palindrome or not (a palindrome numberissymmetrical, ex: 131, 22122)

  20. Homework • Ex1. Write a functionprimeNumberswhichreceives a number (n) as a parameter and displays the first n prime numbers. Test yourfunction in the main. • Ex2. Write a function « factorial » whichreceives a number (n) as a parameter and calculatesitsfactorial. Test yourfunction in the main. • Ex3. Write a program whichchecks if twonumbers are relatively prime. Use a functionwhichreceives the twonumbers as parameters and test it in the main.

More Related