EssayGhost Assignment代写,Essay代写,网课代修,Quiz代考

EssayGhost-Essay代写,作业代写,网课代修代上,cs代写代考

一站式网课代修,论文代写

高质量的Assignment代写、Paper代写、Report代写服务

EG1hao
网课代修代上,cs代写代考
Web作业代写
您的位置: 主页 > 编程案例 > Web作业代写 >
Web作业代做:Homework Lecture Lab1 代写编程程序 - Web作业代写
发布时间:2021-07-24 18:12:13浏览次数:
ILogical AND ( ) : returns true if both operands are true; returns false otherwisea == 3 d == a ILogical OR (jj) : return true if either or both operands is true; returns false otherwisea == 3 || d == a IModulo % (to nd the remainder from integer division): int x = 7 % 3; Operators: Short-cutsWe have some short-cuts; e.g. For an int value i:IIncrement:i++; // same as, i = i+1;i += 17; // same as, i = i+17;IDecrement:i // same as, i = i 1;i -= 21; // same as, i = i 21;IMultiplication:i *= 13; // same as, i = i*13;IDivision:i /= 42; // same as, i = i / 42; Pre x and Post xIPost x:Iincrement x and return old x:int x = 3; int y = x++;Inow, y == 3 and x == 4IPre x:Iincrement x and return new valueint x = 3; int y = ++x;Inow, y == 4 and x == 4 Functions C++ FunctionsIWe saw the main() function { every application has to have a main().IWe do NOT write the entire program in the main function.IWe use functions and classes.IIt is easier to solve a complex problem by breaking it up into smaller parts.IAnd, combine them to solve the problem.IWe write a function to do a certain task or a sub task.ICombine one/more functions to solve a problem.IUsing functions have several advantages.IFirst, let s learn how to write functions in C++.IExample: we can write a function to display a greeting message on the screen:void DisplayGreeting(){std::cout Hello World! std::endl;} IA C++ function:Ihas a name2Itakes zero or more argumentsIusually does something in the function bodyIreturns some value of a certain typeIif a function does not return anything, its return type is void2We can also write a function without name Functions: Example 1IOur rst function writes the greeting, Hello World! to the screen:#includevoid DisplayGreeting(){std::cout Hello World! std::endl;}IWe can now call this function from the mainfunction:int main(){DisplayGreeting();return 0;} Functions: Example 2IHow would you write a function to add two integers?int Add(int a, int b){return a+b;}int main(){int result= Add(2, 3);cout Result : result endl;} Functions: Advantages1.Better/simpler solution: divide the problem into smaller tasks.2.Better code structure: improve readability/clarity.3.Reuse: once a function is written, we can use it any number of times.4.Maintainability: we write a function once, if we want to make a chance, x a bug, we can do it just in one place.5.Type safety:Iarguments passed to a function should match the types in the function declarationIprogram will not compile if there s a mismatch Parameter OverloadingIOverloading allows 2 or more functions to have the same name:Ithey must have di erent input argument typesIthey cannot di er by the return type onlyIAllows us to write more than one method to do some task in di erent ways, using di erent inputs.IFor example, we can write another Add() function as:double Add(double a, double b){return a+b;} In-Class ExercisesIWrite functions to add:1.two oat values2.3 integer values3.3 double values Implicit Type ConversionsISuppose we have the following function:double Add(double a, double b){return a+b;}IWhat happens if we use it to add two integer values:int main(){int a = 2; int b = 3;cout Add(a, b) endl;}IQuestion: does this program build? IYes, this program builds just ne:Iarguments are passed to the function as doublesIsize of int is 4 bytes; double is 8 bytesIwe can safely store any int value in a doubleIC++ (compiler) converts the int to double (implicitly) in this case.IThis is a conversion from a smaller (4 byte) to a larger (8 byte) type.IIt is called a widening, or, promotionIPromotions are safe implicit conversions. ISuppose we have the following function:int Add(int a, int b){return a+b;}IWhat happens if we use it to add two double values:int main(){double a = 2.2; double b = 3.3;cout Add(a, b) endl;}IWill this program build? IYes, this program also builds:Iarguments are passed as intsIsize of double is 8 bytes; int is 4 bytesIwe cannot safely convert every double value to an intIC++ (compiler) converts the double do int values implicitly in this case.IResults in a conversion from a larger (8 byte) to a smaller (4 byte) type.IIt is called a narrowing.INarrowing can be dangerous, and results in a build Warning.IWhy is this not an error?IC++ expects us to know what we re doingIC++ will let you shoot yourself in the foot if we re not careful ILesson: Pay Attention to Build Warnings! CastingIWhat s the result from integer divsion below:int a = 3, b = 2;cout a / b endl;ITo get the correct (real) number, we must convert at least one operand to real.IExplicit type conversions are known as casting.ICasts are not encouraged, sometimes they are necessary.IC++ supports 4 types of casts (known as named casts).IWe ll look at static_cast now:Istatic_cast:IUsed to force conversions, e.g. int- doubleint a = 3; int b = 2;cout static_castIstatic_cast returns a double value in this case. DemosIImplicit type conversions:IwideningInarrowingIstatic castIHandling syntax errors:1.build logs: errors and warnings2.IntelliSense3: makes coding covenientIDebugging3https://msdn.microsoft.com/en-us/library/dn957937.aspx C++ and Header FilesIWe wrote all code in the same le.IIn practice we never write all code in the same le:Idi cult to read a very large le (with thousands of lines of code)Idoesn t promote reusabilityIdi cult for multiple programmers to work on the same projectImakes build process longerISolution is to use separate les for functions/classes etc.IThis requires using:IC++ lesIHeader les ILet s illustrate how to implement a function(or related functions) in a separate C++ le.ILet s use the add functions as an example:IWe will implement the Add() functions in a separate Add.cpp le.IWhen we move the add functions to a new le our program won t build.IThe main() function doesn t know about the Add() functions.IWe need to declare a function before we can use it in a separate le.IWe could add the following two declarations before we use them in main:int Add(int, int);double Add(double, double);IThis solution is not ideal: it requires us to have these declarations in every le we use them. IProper C++ way:IWrite the function declarations in a header le (e.g. Add.h):int Add(int, int);double Add(double, double);IInclude it in source les, using #include preprocessor directive:#include Add.h In-Class ExerciseIUsing one (or more) Add() function/functions from the previous exercise, write:1.function de nition in the header le.2.function implementation in the cpp source le.3.call the Add() function from main(). C++ Build ProcessC++ build process uses several steps:1.Preprocessing:Iuses the preprocessorIthe preprocessor handles the preprocessor directives (e.g. #include)Ithe output of this step is a C++ le without preprocessor directives1.Compiling:Iuses the compilerIchecks syntaxImakes sure the data types are compatible with the operationsIeach .cpp le is compiled to create an object le (.obj)2.Linking : Iuses the linkerIcreates an executable (.exe) le using the object les Demo: Build ErrorsIWe can have build errors in each stage.IWe need to have an idea about each stage to x build problems. Type AliasIType aliasing can help make code:1.more readable2.less error proneIConsider the function declaration below which calculates theBlack Scholes price of an Option.double BSPrice(double, double, double, double, double);IError prone: it is not clear what the arguments areIWe can use typedefs here:typedef double OptionPrice;typedef double StockPrice;typedef double Strike;typedef double Expiration;typedef double Rate;typedef double Volatility; OptionPrice BSPrice(StockPrice, Strike, Expiration, Rate, Volatility); The const keywordIThe const keyword is used to de ne a constant value.IIf you try to change the value of a const member, the compiler catches it.const int MaxValue = 10;MaxValue = 20; // = This is an errorIThis is another example of the bene ts of type safety in C++.IWe will discuss other uses of the constkeyword later in the course. CommentsIWe can write comments using C style or C++ style.IC style:/* This is a C style comment */IC++ style:// This is a C++ style comment Assignment 0 (Not Graded)1.Write a function to add two integers.2.Read two integer values from the keyboard.3.Add them using the function you wrote.4.Write the result to console.IIndividual Assignment.IDue: January 13, 2018 by midnight (CST).ITotal points: 0 (Zero)ISubmission (Optional):Clean the solution using Clean Solution under Build tab in Visual Studio.Compress (zip) the folder containing the project.Submit on Canvas: follow Assignments - Assignment 0 link and attach the zip le. Week 1 Summary Visual Studio IDEIWe created our rst application:Iwe create a projectIsolution is a placeholder for one or more projectsITools in Visual Studio IDE:Ieditor to write codeIintellisense supportIbuild toolsIdebuggerIBuild uses 3 steps:Ipreprocessing, compiling and linkingIbrie y discussed each step Data TypesICategories:1.fundamental2.user de nedIWe discussed fundamental types and operatorsICompiler can do implicit type conversions:3.widening/promotion (e.g. int to double)4.narrowing (e.g. double to int)IWe can force type conversions via casting FunctionsImain(): program entry pointIWrite a function to do a certain task or a sub task.ICombine them to write a large program.IFunctions promote:IreadabilityIreusabilityImaintainabilityItype safetyIYou will understand these advantages when we write more code. C++ Standard LibraryICollection of useful classes/functions.IBrie y looked at some features in the iostream header:IstreamsIcoutIcinIIntroduced the std::string type in std::string header.代写计算机编程类/金融/高数/论文/英文本网站支持淘宝 支付宝 微信支付 paypal等等交易。如果不放心可以用淘宝或者Upwork交易!E-mail:[email protected]微信:BadGeniuscs 工作时间:无休息工作日-早上8点到凌晨3点如果您用的手机请先保存二维码到手机里面,识别图中二维码。如果用电脑,直接掏出手机果断扫描。

所有的编程代写范围:essayghost为美国、加拿大、英国、澳洲的留学生提供C语言代写、代写C语言、C语言代做、代做C语言、数据库代写、代写数据库、数据库代做、代做数据库、Web作业代写、代写Web作业、Web作业代做、代做Web作业、Java代写、代写Java、Java代做、代做Java、Python代写、代写Python、Python代做、代做Python、C/C++代写、代写C/C++、C/C++代做、代做C/C++、数据结构代写、代写数据结构、数据结构代做、代做数据结构等留学生编程作业代写服务。