欢迎来到麦多课文档分享! | 帮助中心 海量文档,免费浏览,给你所需,享你所想!
麦多课文档分享
全部分类
  • 标准规范>
  • 教学课件>
  • 考试资料>
  • 办公文档>
  • 学术论文>
  • 行业资料>
  • 易语言源码>
  • ImageVerifierCode 换一换
    首页 麦多课文档分享 > 资源分类 > PPT文档下载
    分享到微信 分享到微博 分享到QQ空间

    C++ Program Structure (and tools).ppt

    • 资源ID:379229       资源大小:139KB        全文页数:15页
    • 资源格式: PPT        下载积分:2000积分
    快捷下载 游客一键下载
    账号登录下载
    微信登录下载
    二维码
    微信扫一扫登录
    下载资源需要2000积分(如需开发票,请勿充值!)
    邮箱/手机:
    温馨提示:
    如需开发票,请勿充值!快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如需开发票,请勿充值!如填写123,账号就是123,密码也是123。
    支付方式: 支付宝扫码支付    微信扫码支付   
    验证码:   换一换

    加入VIP,交流精品资源
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    C++ Program Structure (and tools).ppt

    1、C+ Program Structure (and tools),Today well talk generally about C+ development (plus a few platform specifics) Well develop, submit, and grade code in Windows Its also helpful to become familiar with Linux E.g., on shell.cec.wustl.edu For example, running code through two different compilers can ca

    2、tch a lot more “easy to make” errors,Writing a C+ Program,C+ source files (ASCII text) .cpp,Programmer (you),emacs,editor,C+ header files (ASCII text) .h,1 source file = 1 compilation unit,Also: .C .cxx .cc,Also: .H .hxx .hpp,readme (ASCII text),Eclipse,Visual Studio,What Goes Into a C+ Program?,Dec

    3、larations: data types, function signatures, classes Allows the compiler to check for type safety, correct syntax Usually kept in “header” (.h) files Included as needed by other files (to keep compiler happy)class Simple typedef unsigned int UINT32; public:Simple (int i); int usage (char * program_na

    4、me);void print_i (); private: struct Point2D int i_; double x_; ; double y_;Definitions: static variable initialization, function implementation The part that turns into an executable program Usually kept in “source” (.cpp) filesvoid Simple:print_i () cout “i_ is ” i_ endl; Directives: tell compiler

    5、 (or precompiler) to do something More on this later,A Very Simple C+ Program,#include / precompiler directiveusing namespace std; / compiler directive/ definition of function named “main” int main (int, char *) cout “hello, world!” endl;return 0; ,What is #include ?,#include tells the precompiler t

    6、o include a file Usually, we include header files Contain declarations of structs, classes, functions Sometimes we include template definitions Varies from compiler to compiler Advanced topic well cover later in the semesteris the C+ label for a standard header file for input and output streams,What

    7、 is using namespace std; ?,The using directive tells the compiler to include code from libraries that have separate namespaces Similar idea to “packages” in other languages C+ provides a namespace for its standard library Called the “standard namespace” (written as std) cout, cin, and cerr standard

    8、iostreams, and much more Namespaces reduce collisions between symbols Rely on the : scoping operator to match symbols to them If another library with namespace mylib defined cout we could say std:cout vs. mylib:cout Can also apply using more selectively: E.g., just using std:cout,What is int main (i

    9、nt, char*) . ?,Defines the main function of any C+ program Who calls main? The runtime environment, specifically a function often called something like crt0 or crtexe What about the stuff in parentheses? A list of types of the input arguments to function main With the function name, makes up its sig

    10、nature Since this version of main ignores any inputs, we leave off names of the input variables, and only give their types What about the stuff in braces? Its the body of function main, its definition,Whats cout “hello, world!” endl; ?,Uses the standard output iostream, named cout For standard input

    11、, use cin For standard error, use cerr is an operator for inserting into the stream A member operator of the ostream class Returns a reference to stream on which its called Can be applied repeatedly to references left-to-right “hello, world!” is a C-style string A 14-postion character array terminat

    12、ed by 0 endl is an iostream manipulator Ends the line, by inserting end-of-line character(s) Also flushes the stream,What about return 0; ?,The main function should return an integer By convention it should return 0 for success And a non-zero value to indicate failure The program should not exit any

    13、 other way Letting an exception propagate uncaught Dividing by zero Dereferencing a null pointer Accessing memory not owned by the program Indexing an array “out of range” can do this Dereferencing a “stray” pointer can do this,A Slightly Bigger C+ Program,#include using namespace std; int main (int

    14、 argc, char * argv) for (int i = 0; i argc; +i)cout argvi endl;return 0; ,int argc, char * argv,A way to affect the programs behavior Carry parameters with which program was called Passed as parameters to main from crt0 Passed by value (well discuss what that means) argc An integer with the number o

    15、f parameters (=1) argv An array of pointers to C-style character strings Its array-length is the value stored in argc The name of the program is kept in argv0,for (int i = 0; i argc; +i),Standard (basic) C+ for loop syntax Initialization statement done once at start of loop Test expression done befo

    16、re running each time Expression to increment after running each time int i = 0 Declares integer i (scope is the loop itself) Initializes i to hold value 0 (not an assignment!) i argc Tests whether or not were still inside the array! Reading/writing memory we dont own can crash the program (if were r

    17、eally lucky!) +i increments the array position (why prefix?),cout argvi endl;,Body of the for loop I strongly prefer to use braces with for, if, while, etc., even w/ single-statement body Avoids maintenance errors when adding/modifying code Ensures semantics/indentation say same thing argvi An examp

    18、le of array indexing Specifies ith position from start of argv,Lifecycle of a C+ Program,C+ source code,Makefile,Programmer (you),object code (binary, one per compilation unit) .o,make,“make” utility,xterm,console/terminal/window,Runtime/utility libraries (binary) .lib .a .dll .so,gcc, etc.,compiler

    19、,link,linker,E-mail,executable program,Eclipse,debugger,precompiler,compiler,link,turnin/checkin,An “IDE”,WebCAT,Visual Studio,window,compile,Development Environment Studio,Well follow a similar format most days in the course Around 30 minutes of lecture and discussion Then about 60 minutes of studi

    20、o time Except for open studio/lab days, reviews before the midterm and final, and the day of the midterm itselfIn the studios, please work in groups of 2 or 3 Exercises are posted on the course web page Record your answers to the exercises, and e-mail your answers to the course account when youre done Well migrate throughout the studio to answer questionsUse studio time to develop skills and understanding A good chance to explore ideas you can use for the labs Exams will test understanding of the studio material Youre encouraged to try variations beyond the exercises,


    注意事项

    本文(C++ Program Structure (and tools).ppt)为本站会员(赵齐羽)主动上传,麦多课文档分享仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知麦多课文档分享(点击联系客服),我们立即给予删除!




    关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

    copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
    备案/许可证编号:苏ICP备17064731号-1 

    收起
    展开