美文网首页
on the Heap代做C/C++编程作业

on the Heap代做C/C++编程作业

作者: jrgexe5 | 来源:发表于2019-02-23 16:43 被阅读0次

    <p>代写关于C和C++的五个小练习,对比这两种语言之间的差异。</p>

    <h2 id="Objective">Objective</h2>

    <p>The objective of this lab is focused on a variety of subjects from C to C++. Here is the summary of the some of the topics that are covered:</p>

    <ul>

        <li>Dynamic allocation of memory in C</li>

        <li>C structs with dynamic allocation of memory</li>

        <li>Introduction to C++ reference type</li>

        <li>Introduction to C++ classes</li>

    </ul>

    <p>Note: some of the exercises in this lab are implemented in C and some in C++. For the exercises that you need to compile and run them, please make sure to use the correct compilation commands:</p>

    <ul>

        <li>gcc for C programs</li>

        <li>g++ for C++ programs.</li>

    </ul>

    <h2 id="Exercise-A-Allocation-of-Memory-on-the-Heap">Exercise A: Allocation of Memory on the Heap</h2>

    <p>This is an in-lab exercise.</p>

    <h3 id="Read-This-First">Read This First</h3>

    <p>Before doing this exercise, you should review lecture notes or a C textbook to be sure you know exactly how C library function malloc works.</p>

    <h3 id="What-to-Do">What to Do</h3>

    <p>Download the file lab7ExA.c and lab7ExA.h from D2L.Read these files carefully and draw a memory diagram for point one, assuming that all the calls to the library function malloc succeed.</p>

    <h3 id="What-to-Submit">What to Submit</h3>

    <p>Submit your diagram as part of your in-lab report.</p>

    <h2 id="Exercise-B-C-References">Exercise B: C++ References</h2>

    <p>This is an In-lab exercise</p>

    <h3 id="Read-This-First-1">Read This First</h3>

    <p>The AR notations that we use in ENCM 339 to show C++ references are different from ordinary types such as: int, double, and pointer notations. When we declare a reference we just provide an alias name for another memory space. In other words, a reference in C++ doesn&rsquo;t have its own memory space; therefore we show them as a link (a line) between the reference-identifier and the actual allocated memory spaces. There are two little circles on both ends of these links. On one end there is a solid-black circle that represents the reference, and on the other end there is an open circle that represents the actual allocated memory space. Here are a few examples:</p>

    <p><figure class="highlight c++">

    <table>

        <tbody>

            <tr>

                <td class="gutter">

                <pre><span class="line">1</span><br /><span class="line">2</span><br /><span class="line">3</span><br /><span class="line">4</span><br /><span class="line">5</span><br /></pre>

                </td>

                <td class="code">

                <pre><span class="line"><span class="keyword">int</span> a = <span class="number">40</span>;</span><br /><span class="line"><span class="keyword">int</span>*p = amp;a;</span><br /><span class="line"><span class="keyword">int</span>amp; ra = a;    <span class="comment">// ra is referred to integer a</span></span><br /><span class="line"><span class="keyword">int</span>*amp; rp = p;   <span class="comment">// rp is referred to integer pointer p</span></span><br /><span class="line"><span class="keyword">int</span>amp; rra = ra;  <span class="comment">// rra is also referred to a</span></span><br /></pre>

                </td>

            </tr>

        </tbody>

    </table>

    </figure></p>

    <p>&nbsp;</p>

    <p>Notice that all references ra, rp, and rra must be initialized with an expression that represents an actual memory space or another reference.</p>

    <h3 id="What-To-Do">What To Do</h3>

    <p>Download the file lab7ExB.cpp from D2L. Then, draw an AR diagram for point one.</p>

    <p>Note: You don&rsquo;t need to compile and run this program but in case that you decided to run it, you should use the g++ command which is the command to compile C++ programs in our ICT 320 lab under the Cygwin. The executable file created will be still a.exe, by default.</p>

    <pre><code>g++ -Wall lab7ExB.cpp </code></pre>

    <h3 id="What-To-Submit">What To Submit</h3>

    <p>Submit your diagrams as part of your in-lab report.</p>

    <h2 id="Exercise-C-Objects-on-the-Computer-Memory">Exercise C: Objects on the Computer Memory</h2>

    <p>This is also an In-lab exercise</p>

    <p>The objective of this exercise is to help you in understanding how C++ objects are shown on a memory diagram, and how a member function of a class uses the &lsquo;this&rsquo;pointer to access an object associated with a that particular call to the function. For further details please refer to your lecture notes and slides.</p>

    <h3 id="What-to-Do-1">What to Do</h3>

    <p>Download files cplx.cpp, cplx.h, and lab7ExC.cpp from the D2L and draw AR diagrams for: point one and point two.</p>

    <p>For this exercise also you just need draw the diagrams. However, if you want to compile and run it from command line in our ICT 320 lab, you should have all of the given files in the same directory and from that directory you should use the following command to compile and create an executable:</p>

    <pre><code>g++ -Wall cplx.cpp lab7ExC.cpp </code></pre>

    <p>Please notice that you shouldn&rsquo;t have the header file name(s) in this command.</p>

    <h3 id="What-To-Submit-1">What To Submit</h3>

    <p>Submit your diagram as part of your in-lab report.</p>

    <h2 id="Exercise-D-String-Manipulation-Using-Dynamic-Allocation-in-C">Exercise D: String Manipulation Using Dynamic Allocation in C</h2>

    <p>This is a post lab exercise.</p>

    <p>The main objective of this exercise is to give you the opportunity to practice dynamic allocation of memory in C, for the purpose of string operations such as copying a string into another string, appending a string to the end of another string, or truncating the size of a string.</p>

    <h3 id="Read-This-First-2">Read This First</h3>

    <p>Creating a kind of wrapper data type that encapsulates several related data is a common practice to build data structures such as vectors, string, linked list, trees in object oriented programming languages such as C++. We will discuss the proper way of applying these concepts during the lectures and possibly future labs.</p>

    <p>In this exercise a structure type, called Lab7Text is defined that is similar to the structure given in Exercise A. This structure simply contains two pieces of related data. First one is a pointer that is supposed to point to a dynamically allocated array of characters, used as storage for a null-terminated c-string, called text. Second one is an integer number that represents the length of the stored string in the first data member (number of characters up to but excluding the &lsquo;\0&rsquo;).</p>

    <p>Here is the definition of this structure:</p>

    <p><figure class="highlight c++">

    <table>

        <tbody>

            <tr>

                <td class="gutter">

                <pre><span class="line">1</span><br /><span class="line">2</span><br /><span class="line">3</span><br /><span class="line">4</span><br /></pre>

                </td>

                <td class="code">

                <pre><span class="line"><span class="keyword">typedef</span> <span class="keyword">struct</span> Lab7Text#123;</span><br /><span class="line">  <span class="keyword">char</span> *text;</span><br /><span class="line">  <span class="keyword">int</span> length;</span><br /><span class="line">#125; Lab7Text;</span><br /></pre>

                </td>

            </tr>

        </tbody>

    </table>

    </figure></p>

    <p>&nbsp;</p>

    <h3 id="What-To-Do-First">What To Do First</h3>

    <p>Download the files Lab7Text.c and Lab7Text.h from D2L. In the file Lab7Text.c, there are several functions as follows:</p>

    <p><figure class="highlight c++">

    <table>

        <tbody>

            <tr>

                <td class="gutter">

                <pre><span class="line">1</span><br /></pre>

                </td>

                <td class="code">

                <pre><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">create_empty_text</span> <span class="params">(Lab7Text *txt)</span></span>;</span><br /></pre>

                </td>

            </tr>

        </tbody>

    </table>

    </figure></p>

    <p>&nbsp;</p>

    <p>Creates an object of Lab7Text that contains a string with one element holding only a &lsquo;\0&rsquo; and its length is zero.</p>

    <p><figure class="highlight c++">

    <table>

        <tbody>

            <tr>

                <td class="gutter">

                <pre><span class="line">1</span><br /></pre>

                </td>

                <td class="code">

                <pre><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">set_c_string</span><span class="params">(Lab7Text *tx, <span class="keyword">const</span> <span class="keyword">char</span>* s)</span></span>;</span><br /></pre>

                </td>

            </tr>

        </tbody>

    </table>

    </figure></p>

    <p>&nbsp;</p>

    <p>Copies a c-string from s into the dynamically allocate space in the object that tx points to.</p>

    <p><figure class="highlight c++">

    <table>

        <tbody>

            <tr>

                <td class="gutter">

                <pre><span class="line">1</span><br /></pre>

                </td>

                <td class="code">

                <pre><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">text_append</span><span class="params">(Lab7Text *tx, <span class="keyword">const</span> Lab7Text* tail)</span></span>;</span><br /></pre>

                </td>

            </tr>

        </tbody>

    </table>

    </figure></p>

    <p>&nbsp;</p>

    <p>Expands the length of dynamically allocated space for the c-string in tx to allow appending the c-string from the object that tail points at, to the end of the c-string inside the object that tx points at.</p>

    <p>In this file in addition to a main function and the above-mentioned functions there are also three test-function for testing function: text_copy, text_append, and text_truncate.</p>

    <p>Here is the first step, before your tasks starts: Compile and run the program and find out how functions set_c_string and text_append work. The function test_appending should produce an output that its first few lines and the last line are as follows.</p>

    <p>As this output shows for each call to the function text_append or function set_c_string it tells you what is expected to be displayed, and then in the following line the actual output which is a string and its length, is displayed.</p>

    <h3 id="What-To-Do-Second">What To Do Second</h3>

    <p>Your next task in this exercise is to write the implementation of two missing function text_copy and function text_truncate, according to the given interface comments in the file Lab7Text.h. You are advised to write and test one function at a time, and once the function works with no errors, start working on the next function.</p>

    <p>To complete this task, please take exactly the following steps:</p>

    <ol>

        <li>In the main function, change the conditional-compilation-directive for the call to test_copying from <code>#if 0</code> to <code>#if 1</code>.</li>

        <li>Read carefully the function interface comment for function text_copy in the header file Lab7Text.h and write the implementation of this function.</li>

        <li>Compile and run the program and make sure the test results matches with expected output indicated by the function test_copying. Once all tests passes successfully, go to the next step</li>

        <li>Change the conditional-compilation-directive for the call to test_truncating from <code>#if 0</code> to <code>#if 1</code>.</li>

        <li>Read carefully the function interface comment for function text_truncate and write the implementation of this function.</li>

        <li>Compile and run the program and make sure the test results matches with expected output indicated by the function test_truncating. Once all tests passes successfully, you are done with this exercise.</li>

    </ol>

    <h3 id="What-To-Submit-2">What To Submit</h3>

    <p>In your post-lab PDF file, include listings of the final versions of your Lab7Text.c, and a listing of the output of the final version of your program.</p>

    <h2 id="Exercise-E-Writing-a-Class-Definition-and-Its-Implementation">Exercise E: Writing a Class Definition and Its Implementation</h2>

    <p>This is a post-lab exercise</p>

    <h3 id="Read-This-First-What-is-a-Helper-Functions">Read This First - What is a Helper Functions?</h3>

    <p>One of the important elements of good software design is the concept of code-reuse. The idea is that if any part of the code is repeatedly being used, we should wrap it into a function, and then reuse it by calling the function as many times as needed. In the past labs in this course and the previous programming course, we have seen how we can develop global function to reuse them as needed. A similar approach can be applied within a C++ class by implementing helper-functions. These are the functions that are declared as private member functions and are only available to the member functions of the class &ndash; Not available to the global functions such as main or member functions of the other classes.</p>

    <p>If you pay close attention to the given instruction in the following &ldquo;What to Do&rdquo; section, you will find that there are some class member functions that need to implement almost a similar algorithm. They all need to change the value of data members of the class in more or less similar fashion. Then, it can be useful if you write one or more private helper-function, that can be called by any of the other member functions of the class, as needed.</p>

    <h3 id="Read-This-Second-Defining-Class-Clock">Read This Second - Defining Class Clock</h3>

    <p>In this exercise you are going to design and implement a C++ class called, Clock that represents a 24-hour clock. This class should have three private integer data members called: hour, minute, and second. The minimum value of these data members is zero and their maximum values should be based on the following rules:</p>

    <ul>

        <li>The values of minute, and second in the objects of class Clock cannot be less than 0 and more than 59.</li>

        <li>The value of hour in the objects of class Clock cannot be less than 0 and more than 23.</li>

        <li>As an example any of the following values of hour, minute, and second is acceptable for an object of class Clock (format is hours:minutes:seconds) : 00:00:59, 00:59:59, 23:59:59, 00:00:00. And, all of the following examples are unacceptable:

        <ul>

            <li>24:00:00 (hour cannot exceed 23)</li>

            <li>00:90:00 (minute of second cannot exceed 59)</li>

            <li>23:-1:05 (none of the data members of class Clock can be negative)</li>

        </ul>

        </li>

    </ul>

    <p>Class Clock should have three constructors: A default constructor, that sets the values of the data-members hour, minute, and second to zeros.</p>

    <p>A second constructor, that receives an integer argument in seconds, and initializes the Clock data members with the number of hour, minute, and second in this argument. For example if the argument value is 4205, the values of data members hour, minute and second should be: 1, 10, and 5 respectively. If the given argument value is negative the constructor should simply initialize the data members, all to zeros:</p>

    <p>The third constructor receives three integer arguments and initializes the data members hour, minute, and second with the values of these arguments. If any of the following conditions are true this constructor should simply initialize the data members of the Clock object, all to zeros:</p>

    <ul>

        <li>If the given values for second or minute are greater than 59 or less than zero.</li>

        <li>If the given value for hour is greater than 23 or less than zero.</li>

    </ul>

    <p>Class Clock should also provide a group of access member functions (getters, and setters) that allow the users of the class to retrieve values of each data member, or to modify the entire value of time. As a convention, lets have the name of the getter functions started with the word get, and the setter functions started with word set, both followed by an underscore, and then followed by the name of data member. For example the getter for the data member hour should be called get_hour, and he setter for the data member hour should be called set_hour. Remember that getter functions must be declared as a const member function to make them read-only funcitons.</p>

    <p>All setter functions must check the argument of the function not to exceed the minimum and maximum limits of the each data member. If the value of the argument is below or above the limit the functions are supposed to do nothing.</p>

    <h3 id="What-To-Do-1">What To Do</h3>

    <p>If you haven&rsquo;t already read the above sections &ldquo;Read This First&rdquo; and &ldquo;Read This Second&rdquo;, read them first. The recommended concept of helper function can help you to reduce the size of repeated code in your program. Then, download file lab7ExE.cpp from D2L. This file contains the code to be used for testing your class Clock.</p>

    <p>Now, take the following steps to write the definition and implementation of your class Clock as instructed in the above &ldquo;Read This Second&rdquo; section.</p>

    <ol>

        <li>Create a header file called lab7Clock.h and write the definition of your class Clock in this file. Make sure to use the appropriate preprocessor directives (#ifndef, #define, and #endif), to prevent the compiler from duplication of the content of this header file during the compilation process.</li>

        <li>Create another file called lab7Clock.cpp and write the implementation of the member functions of class Clock in this file (remember to include &ldquo;lab7Clock.h&rdquo; ).</li>

        <li>Compile files lab7ExE.cpp (that contain the given main functions) and lab7Clock.cpp to create your executable file.</li>

        <li>If your program shows any compilation or runtime errors fix them until your program produces the expected output as mentioned in the given main function.</li>

        <li>Now you are done!</li>

    </ol>

    <h3 id="What-To-Submit-3">What To Submit</h3>

    <p>Submit your source code, lab7Clock.h, and lab7Clock.cpp, and the program&rsquo;s output as part of your post-lab report on the D2L, Dropbox.</p><br>

    <br>本团队核心人员组成主要包括硅谷工程师、BAT一线工程师,精通德英语!我们主要业务范围是代做编程大作业、课程设计等等。

    我们的方向领域:window编程 数值算法 AI人工智能 金融统计 计量分析 大数据 网络编程 WEB编程 通讯编程 游戏编程多媒体linux 外挂编程 程序API图像处理 嵌入式/单片机 数据库编程 控制台 进程与线程 网络安全  汇编语言 硬件编程 软件设计 工程标准规等。其中代写编程、代写程序、代写留学生程序作业语言或工具包括但不限于以下范围:

    C/C++/C#代写

    Java代写

    IT代写

    Python代写

    辅导编程作业

    Matlab代写

    Haskell代写

    Processing代写

    Linux环境搭建

    Rust代写

    Data Structure Assginment 数据结构代写

    MIPS代写

    Machine Learning 作业 代写

    Oracle/SQL/PostgreSQL/Pig 数据库代写/代做/辅导

    Web开发、网站开发、网站作业

    ASP.NET网站开发

    Finance Insurace Statistics统计、回归、迭代

    Prolog代写

    Computer Computational method代做

    <br>

    <span STYLE="color:white;background:red;mso-highlight: red">因为专业,所以值得信赖。如有需要,请加QQ:99515681 或邮箱:99515681@qq.com 微信:codehelp </span>y

    相关文章

      网友评论

          本文标题:on the Heap代做C/C++编程作业

          本文链接:https://www.haomeiwen.com/subject/myupyqtx.html