C + + Quiz code

Source: Internet
Author: User

1 /*2 returns the first n bits of the string and the first n bits of the returned integer3 */4 5#include <iostream>6 7UnsignedLongLeft (unsignedLongNumintn);8 Char* Left (Char* STR,intn);9 Ten using namespacestd; One  A intMain () - { -UnsignedLongnum; the     intN; -cout <<"Please enter an integer:"; -CIN >>num; -cout <<"Please enter the number of digits to intercept:"; +CIN >>N; -cout <<"before"<< N <<"bit is"<< left (num, n) <<Endl; +  A     Char* str =New Char( -); atcout <<"Please enter a string:"; -CIN >>str; -cout <<"Please enter the number of digits to intercept:"; -CIN >>N; -cout <<"before"<< N <<"bit is"<< left (str, n) <<Endl; -  in     //delete[] str; -  toCin.Get(); +Cin.Get(); - } the  *  $UnsignedLongLeft (unsignedLongNumintN)Panax Notoginseng { -UnsignedLongLen =1;//indicates that there are several theUnsignedLongTemp_num =num; +      while(Temp_num/=Ten) A     { thelen++; +     } -UnsignedLongCut_num_len = Len-(unsignedLong(n) >= Len? len:unsignedLong(n));//when n is less than the length of an integer, the original integer is retrieved directly $      while(cut_num_len--) $     { -Num/=Ten; -     } the     returnnum; - }Wuyi  the Char* Left (Char* STR,intN) - { Wu     intLen =strlen (str); -n = n >= len?len:n; About     Char* Temp_char =New Char(n +1); $  -      for(inti =0; I < n; i++) { -* (Temp_char + i) = * (str +i); -     } ATemp_char[n] =' /'; +     returnTemp_char; the}

Everybody look down, there's a problem when I cancel //delete[] str; Note, the program will error, not to encourage if it is a new self-made pointer is the best to delete it? Ask the right answer.

C + + Quiz code

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.