freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

c程序設計語言習題答案-閱讀頁

2025-07-10 15:46本頁面
  

【正文】 cout 歡迎使用桌面計算器 endl。 cout請在標識符的后面加上一個空格,否則程序將會出錯endl。 cout 3. 若想退出程序,請輸入endl。cin。 //符號表賦初值table[e]=。 if(Lexer::curr_tok==Lexer::END) break。 coutParser::expr(false)endl。 if(Lexer::curr_tok!=Lexer::PRINT) Driver::skip()。 if(Lexer::curr_tok!=Lexer::PRINT) Driver::skip()。std::cin) delete Driver::input。 return Driver::no_of_errors。include iostream include string using namespace std。 Stack(){ top = 1。 void push(int n)。 //彈棧操作 bool isEmpty()。 //判斷棧是否滿? void dump()。 private: int top。 }。 else { top ++。 }}int stack::Stack::pop(){ if(isEmpty()) coutError,the Stack is empty!\n。}bool stack::Stack::isFull(){ if(top == Max1) return true。}bool stack::Stack::isEmpty(){ if( top == 1) return true。}void stack::Stack::dump(){ for( int i = top。i) coutarray[i] 。 const int M = 10。 int a[ M ]。 for(int i = 0。 i ++) { cina[i]。 } cout 再壓進一個數(shù)看看: endl。 cin b。 cout 以下是你輸入的十個數(shù)的展示: endl。 cout \n進行彈棧操作,以下是彈出的數(shù)字: endl。j M。 cout \n再進行一次彈棧操作: endl。 cout 測試工作結束 endl。 return 0。//該方法使用數(shù)組來實現(xiàn)的,當然可以直接實現(xiàn)queue 讀者自己實現(xiàn)includeiostreamincludecstdlibusing namespace std。 int elemnum。 int head,tial。 void addhead(int x)。 y)。 int deltial()。}}。 head=0。}void List::addhead(int x) { int i。} else for(i=elemnum1。i) elems[i+1]=elems[i]。 elemnum++。}void List::addtial(intamp。} elems[tial]=y。 elemnum++。 return 1。 s=elems[head]。itial。 elemnum。 return s。 return 1。 s=elems[tial1]。 elemnum。 }}//class stack:public List{//讀者可以參考stack類。// int pop()。//}。}//int stack::pop()//{return deltial()。}class Queue:public List{//queue繼承自List public: //Queue():List(){}//可要可不要 void enqueue(int x)。 int getqueuenum()。void Queue::enqueue(int x) { addtial(x)。}int Queue::getqueuenum() { return get_num()。List l1。i23。cout() ()endl。cout()endl。int h,a。test: \n it39。 for(h=45。h++) (h)。 coutaendl。ha。 coutendl。 return 0。int Atoi(const char* str){ int result = 0。 for(int i = 0。\039。 for(int i = size1。 i) result += (str[i] 39。)*static_castint(pow(10, static_castdouble(sizei1)))。 system(pause)。}2)寫一測試程序,將命令行中傳入的字符串調用atoi函數(shù)將其轉換成整數(shù)并輸出。 int i = 0。 cout Atoi(()) endl。}2.將第7章桌面計算器的程序的每一個模塊寫成一個C++源文件,然后采用分別編譯技術和include指令將其組裝起來。第九章 練習題:1. 什么是類(class)?在類的定義中,類由哪兩部分組成?每一部分各表示什么?答:一個C++類(class)是一個用戶自定義(Userdefined)類型。其中數(shù)據(jù)成員即類中各變量/對象的定義部分,它們描述了該類對象所具有的屬性,各數(shù)據(jù)成員值集的笛卡爾積構成了該類型的值集。2. 給定以下程序:include iostreamusing namespace std。}在不修改main函數(shù)的前提下,修改上述程序使之產(chǎn)生如下輸出:InitializeHello, wele you study C++!Clean up解:include iostreamusing namespace std。 ~C ()。}。}C::~C(){ cout Clean up endl。int main () { cout Hello, wele you study C++!\n。}3. 設計并實現(xiàn)一個整型堆棧類(Stack),該類具有以下操作:a) void push(int n)。 //彈棧操作c) bool isEmpty()。 //判斷棧是否滿?e) void dump()。class Stack{ //類的接口public: enum{ Max = 10}。 }。 //壓棧操作 int pop()。 //判斷棧是否為空? bool isFull()。 //自棧頂向下讀取堆棧中的元素 ~Stack(){}。 int array[ Max ]。 //類的實現(xiàn)void Stack :: push( int n ){ if( isFull() ) coutError,the Stack is full\n。 array[ top] = n。 else return array[top]。 else return false。 else return false。i = 0。}int main()//測試棧{ const int M = 10。 int a[ M ]。 for(int i = 0。 i ++) { cina[i]。 } cout 再壓進一個數(shù)看看: endl。 cin b。 cout 以下是你輸入的是個數(shù)的展示: endl。 cout \n進行彈棧操作,以下是彈出的數(shù): endl。j M。 cout \n再進行一次彈棧操作: endl。 cout 測試工作結束 endl。}4. 設計并實現(xiàn)一個和基本類型int功能類似的MyInteger類,該類對外提供如下操作:a) int add(int x1, int x2)。 //減法操作c) int mul(int x1, int x2)。 //除法操作e) int mod(int x1, int x2)解:includeiostreamusing namespace std。const int Min = 32768。 } MyInteger add(MyInteger x)。 //減法操作 MyInteger mul(MyInteger x)。 //除法操作 MyInteger mod(MyInteger x)。private: int result。MyInteger MyInteger::add(MyInteger x){ int i = result。 cout i 和這兩個數(shù)的和是resultendl。}MyInteger MyInteger::sub(MyInteger x){ int i = result。 return 0。 couti和這兩個數(shù)的差是resultendl。}MyInteger MyInteger::mul(MyInteger x){ int i = result。 return 0。 couti和這兩個數(shù)的積是resultendl。}MyInteger MyInteger::div(MyInteger x){ int i = result。 return 0。 return NULL。 couti和這兩個數(shù)的商是resultendl。}MyInteger MyInteger::mod(MyInteger x){ int i = result。 return 0。 return NULL。 couti和這兩個數(shù)的余數(shù)是resultendl。}int main(){ MyInteger m1( 12 ),m2( 6 )。 MyInteger m3( 45 ),m4( 8 )。 MyInteger m5( 1123 ),m6( 0 )。 MyInteger m7( 6347 ),m8( 67 )。 system(pause)。}5. 設計并實現(xiàn)一個Date日期類,其中該類對外提供多種對象生成方式,且具有讀取和修改日期對象值的若干方法。class Date{//默認了一個copy constructorpublic: Date(){ Year = 1970。 Day = 1。 Date( char* s)。 int const getMonth( )。 void setYear( int)。 void setDay( int)。}。 if( m = 12 amp。 m = 1) Month = m。 if( d = 31 amp。 d 0) Day = d。}Date::Date( char* s){ int l = strlen( s )。039。039。039。039。 Month = (*(s + 4) 39。) * 10 + (*(s + 5) 39。 ) * 1 。039。039。 } if(l == 7){ Year = (*s 39。) * 100 + (*(s + 1) 39。) * 10 + (*(s + 2) 39。) * 1 。039。039。 Day = (*(s +5) 39。) * 10 + (*(s +6) 39。) * 1。}int const Date::getMonth( ){ return Month。}void Date::setYear( int Y ){ Year = Y。}void Date::setDay(int D ){ Day = D。 cout D1: year= () month= () day= () endl。 ( 2008 )。 (1)。 cout D3: year= () month= () day= () endl。 cout D4: year= () month= () day= () endl。}6. 根據(jù)以下類的界面定義,完成類Table各方法的實現(xiàn)。 //表示人名的字符串 int
點擊復制文檔內(nèi)容
醫(yī)療健康相關推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1