0% found this document useful (0 votes)
142 views22 pages

DSA Lab1

This document outlines the grading structure, homework assignments, and objectives for a Data Structures and Algorithms lab course. The lab is worth 50% of the final grade based on homework assignments and in-class activities. Students must attend 10 out of 13 lab sessions and earn a 5 out of 10 on homework and labs to pass. The document also provides information on tools, standard input/output operations, functions, structures, and sample homework assignments.

Uploaded by

dukeyasser107967
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
142 views22 pages

DSA Lab1

This document outlines the grading structure, homework assignments, and objectives for a Data Structures and Algorithms lab course. The lab is worth 50% of the final grade based on homework assignments and in-class activities. Students must attend 10 out of 13 lab sessions and earn a 5 out of 10 on homework and labs to pass. The document also provides information on tools, standard input/output operations, functions, structures, and sample homework assignments.

Uploaded by

dukeyasser107967
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

DATASTRUCTURESAND

ALGORITHMS
LAB1
MelaniaNiu
[email protected]
FILS,2017
GRADING

Thelabrepresents50%ofthefinalgrade:
30%-3BigHomeworks
20%-Labs(in-classactivity+smallhomeworkfromweektoweek)
Bonusesforexceptionalhw

Conditionsforpassing:
10presencesatthelab(max13presences)
5outof10forhw+labs(ifnot,thelabwillhavetoberedothenext
yearandthestudentswontbeallowedintheexam)
HW+GRADING

The3mainassignmentsandthelabswillbepublishedonMoodle(fils.curs.pub.ro,
sectionCTI(E)-DataStructuresandAlgorithms).

Youwillusethesameplatformtouploadthehomeworks(withinthedeadline)and
youwillhavetopresentthemduringthenextlaboratory.Ifthereisanyproblemwith
theplatform,youcansendthehomeworksbyemail.

Yourcodewillbecheckedusingasoftwareagainstplagiarism.Twoalmostidentical
homeworkswillbenotedwith0points.

Youcanconsultthegradesforthelaboratoryat:
https://docs.google.com/spreadsheets/d/1fBgZ2CUe05fv1fvO766Qu9Vg52oycfjtrS00RNrnP9Q/edit#gid=1
816440752
QUESTIONS

Foranyotherquestionyoucancontactme
viaemail:[email protected]

YoucanusetheforumonMoodlewhereyou
canalsofindthecoursesandthe
laboratories.(http://fils.curs.pub.ro)
TOOLS

Code::Blocks(http://www.codeblocks.org/downloads)
C-Free4.0Standard/C-Free5.0Professional

AnyotherIDEorcompilerforC/C++
(ex.GCCunderLinux,C-free)
OBJECTIVES

torunandcompileCprograms
toidentifythestructureofaCprogram
tousestandardI/Ooperations
todefinevariables
todeclareandimplementfunctions
tomakestructures
IDENTIFYTHESTRUCTUREOFATYPICALC
PROGRAM!

ThestructureofaCprogram:
Pre-processingdirectives:stdio.hheaderfilefromtheClibrary,necessaryforusing
theprintfandscanffunctions
Oneormorefunctions(themainfunctionisnecessaryforaCprogramtobe
executed),withconditionalstructures,loopinstructionsetc.

Attention, C is case sensitive!


ACprogramiswritteninafilewiththe.cextension:thesourcecode.
Aftercompilation,anotherfile,withthe.oextensionappears:theobjectcode.
Afterexecution,anotherfile,withthe.exeextensionappears:theexecutable.
STANDARDOUTPUTOPERATIONS

Otherformatspecifiers:
SIGNATURE OF PRINTF FUNCTION

printf(control, par1, par2, , parn);

Where
control=astringwhichdefinesthetextsandtheformatsspecifiers
par1, par2, , parn =expressions;theirvaluesarewrittentakinginto
accounttheformatspecifiersfromcontrol(sameorder)

Exercise:Testtheformatspecifiersofthefunctionprintf.
EXCERCISE

Runthebelowexampleandseehoweachformatspecifierworks

#include<stdio.h>
intmain(void){
printf("%d\n",7);
printf("%3d\n",7);
printf("%03d\n",7);
printf("%3.2f\n",5.1);
printf("%.2f\n",4.245);
printf("%s\n","blue");
return0;
}
STANDARDINPUTOPERATIONS

Scanfhasthesamesignatureasprintfanditisdefinedinstdio.h.
EXERCISE

EX1:Writeaprogramtocalculatetheaveragebetween
twofloatnumbers.Theresultshallbedisplayedwith2
decimals.Usescanfandprintf!

Hint:%.2f->formatspecifierforfloatwith2decimals
FUNCTIONS:DECLARATIONANDIMPLEMENTATION
Signature:
type_of_the_returned_resultfunction_name(list_of_formal_params){
declaration_of_local_variables;
instructions;
}
Visibilitydomain:localvs.globalvariables
Parameterpassing:by-value(thevalueoftheformalparameteris
modifiedonlyinthelocalfunction,thevariablefrommainfunctionisnot
affected);wewilldiscussthepassingby-addressduringthelabwiththe
pointers.
GOLDBACHEXAMPLE

Notetheuseofmath.hlibrary:forsqrt
function(thesamemeaningasinJava)

Notethecontrolflowstructures(if,if-
else,for,)

Notethefunctiondefinitionandcall:
theimplementedfunctioncalculatesif
anumberisprimeornot
EXERCISES

EX2:Checkwhetheranumberisapalindromeornot.
Hint:apalindromeisanumberthatremainsthesamewhenits
digitsarereversed.(e.g.333isapalindrome,123isnotapalindrome)

Ex3:Displaytheminimumfromthethreefloatnumbers.

Ex4:Writeaprogramthatcalculatesthesumofthedigitsforall
integersinaninterval.Thelimitsoftheintervalarereadfromthe
keyboard.
STRUCTURES

auser-defineddatatypethatallowsgroupingofheterogeneouselements
acollectionofoneormorevariables(fields),groupedunderonename
themembersofastructureareaccessedwith.

Format:struct[structuretag,optional]
{members}
[structurealias]
DATEEXAMPLE
EX:UTILISATION

voidwriteDDMMYYYY(datamyDate)
{
printf(%d%d%4d,myDate.day,
myDate.month,myDate.year);
}
EX5: Designastructureforrepresentingdatesandwritefunctionsthat:
-Checkifavariablevalueofthestructureisavaliddate.
-Calculatethenextdateofagivendate(tomorrow).
-Calculatethedatebeforeagivendate(yesterday).

HOMEWORK

1.Writeaprogramthatreadsanumberfromtheconsoleandwritesbackifthe
numberisoddoreven.
2.Writeaprogramthatprintstheoddnumbersupto25.
3.Rarepolynomialswithintegercoefficientsarepolynomialsoflargedegrees
andmanycoefficientsequalto0.Theycanberepresentedbyadatastructure
definedas:
Writefunctionsforwriting,readingandadditionofrare
polynomials.
Ex:isararepolynomial;isamonom.
HOMEWORK

4.Writeaprogramtocalculatethegreatestcommondivisor
(cmmdc)forany2numbersinsertedfromthekeyboard.
REFERENCESFORTHECOURSE

C++ProgrammingLanguage,BjarneStroustroup
ThinkinginC++,byBruceEckel&ChuckAllison
C++PlusDataStructures,byNellDale
LimbajeleCsiC++pentruincepatori(vol1-C,vol2-C++),by
LiviuNegrescu(enroumain)
Tutorialspoint:http://www.tutorialspoint.com/cprogramming/
CProgrammingandC++Programming:http://www.cprogramming.com/

You might also like