cout<<L'a'<<endl;输出是97,为cout endl是什么意思?

c++提问程序讲解,越详细越好_百度知道
c++提问程序讲解,越详细越好
&c1=i3&#47#include &c2;endl,i2;i3=i1+i2;i1=c1-48;&&;cout&lt:&int i1;int main(){char c1;&c2&iostream&input c2;&input c1;c2=i3%10+48;&i2=c2-48;cout&lt:&c1&&;10+48;c1;cin&cin&gt,c2;&lt,i3;&cout&return 0
我有更好的答案
//c2;///iostream&/定义两个字符变量cout&/10+48;//&改变c2的值 cout&c1;赋值 i2=c2-48;&#47:&;&int main(){ char c1;input c1;//&lt:&&#47,i2; cin&赋值c1=i3/;/&赋值 i3=i1+i2;c2& cin&input c2;/定义三个整型变量
i1=c1-48;&&&&/&#47解;/改变c1的值 c2=i3%10+48;&quot:#include &&读入一个字符变量
int i1;c1&lt,c2;&quot,i3;读入一个字符变量 cout& &显示改变后的c1和c2
return 0;/&&#47
首先你要明白你输入的是字符,然后与数字进行运算,这其实是ASCII的转换后的运算在c++中,48是字符0的ASCII值。如:你输入的c1是a,a的ASCII值是97,所以a-48就是97-48.以此类推
一楼和二楼结合起来就Ok了
#include &iostream& //标准库,包含输入输出流等 //名字空间int main()
//返回值为整型的主函数,程序入口点{ char c1,c2;//定义两个字符变量cout&&&input c1:&;
//输出字符串input c1: cin&&c1;//输入一个字符变量,存放到c1 cout&&&input c2:&;
//输出字符串input c2: cin&&c2;//输入一个字符,存放到c2
int i1,i2,i3;//定义三个整型变量
i1=c1-48;//赋值 i2=c2-48;//赋值 i3=i1+i2;//赋值c1=i3/10+48;//改变c1的值 c2=i3%10+48;//改变c2的值 cout&&c1&&& &&&c2&&//输出c1(空格)c2,回车,刷新缓冲区
//返回0,表示正常退出}消息来源华夏联盟
其他类似问题
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁C++编程题目_百度知道
C++编程题目
最后调用输出函数在屏幕上输出两个学生的信息。编写主函数;(2)一个输入函数,用于初始化学生姓名、学号,用于屏幕输出学生的所有信息;(3)一个输出函数:(1)一个带函数参数默认值的构造函数、年龄和成绩,用于键盘输入学生的信息建立一个名为CStudent的类:不带参数调用构造函数声明一个学生对象;带参数调用构造函数声明另一个学生对象,调用输入函数输入该学生的信息、性别、学号、性别。还有以下几个函数成员、年龄和成绩:学生姓名,该类有以下几个私有成员变量
再利用CShape类分别定义两个派生类CRectangle(表示矩形)和CCirle(表示圆),在主函数中声明基类指针和派生类对象。三个类都有计算对象面积的成员函数GetArea()和计算对象周长的成员函数GetPerimeter()定义一个CShape抽象类,并通过基类指针调用不同对象的计算面积和周长的成员函数
提问者采纳
/GetPerimeter(); &调用输出函数在屏幕上输出两个学生的信息 s2;void main(){ CStudent s1、学号; Id & 第二题class CShape{
cout &&输入性别&
/ virtual float GetPerimeter() { return 2*PI*R;.14class CC SGetPerimeter();/基类在校人员的声明{ string N delete p2:R(r) {};/成绩;GetArea();& }:class
/GetArea();学号 string M endl, & delete p1;&}, int id=0; //&gt: CStudent(const string name=&&&
cout && (2)一个输入函数:&quot,4);/输入学号& 先做第一题;fmale& p1-> {
cout &}:&quot, float h); & &&&gt,H;输出数据成员的函数(不含编号) {
cout & virtual float GetPerimeter() { return 2*(W+H);
cout &姓名; p1-& &quot, const string male=&&lt, 100); &&lt, Id(id);;//
cout &带参数调用构造函数声明另一个学生对象 s1;&&& Name &lt:&性别 int
Age,H(h) {}; CShape *p2 = new CCirle(3): CRectangle( &
cin &gt.Output();& Score &性别;& Age & &quot, 10;
&lt.Input(); &&输入年龄&void main(){ CShape *p1 = new CRectangle(3;&lt: CCirle(float r);
cout & virtual float GetPerimeter() = 0; /};//
cout &lt:&学生姓名 int
Id, int age=0;//&#47, Male(male);&& }、年龄和成绩;
/ };/调用输入函数输入该学生的信息 CStudent s2(& Age: public CShape{ float W;&lt, 20: public CShape{ float R;&输入成绩&/ &lt,用于初始化学生姓名,用于键盘输入学生的信息,Score(score) { } void Input() /&
cout &xs2& virtual float GetArea() { return PI*R*R;
/不带参数调用构造函数声明一个学生对象 s1、性别;学号;
cin &/class CR Male && &#define PI
3;&输入姓名&quot,Age(age);&
/(1)一个带函数参数默认值的构造函数;};年龄 int
S &} =================================================================/ Id: virtual float GetArea() = 0; virtual float GetArea() { return W*H; & & &&& } void Output( ) / endl:W(w).Output();&
cin & M&成绩;
cin &&/ }};/年龄; &&#47:&quot, int score=0) / & p2-& p2-&gt: Name(name); &
cin & N endl
其他类似问题
其他3条回答
strcpy(N&quot,void
S1(9900101.Print();&lt, char *n,n),20;Age&
strcpy(S\&调用派生类构造函数
Sex[4];string&&/& CJ=c;class
/ int CJ;Sex&lt,s);
/Name&\输出数据成员的函数(不含编号)
CStudent(;iostream&gt,90);/&lt:&t性别;&;}
void Print( )/
};&lt, char *s;\&基类在校人员的声明
Id;男&quot:&基类构造函数
Id=i;&lt,&t成绩:&张三&
Name[20]只做一题吧 #include &#include &CJ;
GetId()&#47:&姓名; 获取编号的函数
{return Id;&t年龄,int c)
/&& Age=a; int
#include&cstring&//这是我改的程序 希望对你有所帮助#include&iostream&int palin(char *a){ int n=0; char *b=NULL;
for(int i=0;*(a+i)!='\0';i++)
if((*(a+i)&=65&&*(a+i)&=90)||(*(a+i)&=97&&*(a+i)&=122))
b=new char[n+1];
//在c++中//如果有指针 并且希望她象动态数组一样使用 请先申请空间 不过字符串长量//不用申请
b[n]='\0'; for(i=0;*(a+i)!='\0';i++)
if((*(a+i)&=65&&*(a+i)&=90)||(*(a+i)&=97&&*(a+i)&=122)) //这里的条件语句有点问题 请你仔细思考下
*(b+n)=*(a+i),n++;
int yesno=1;
for(int x=0,y=n-1;x&y;x++,y--)
if(*(b+x)-*(b+y)!=0&&*(b+x)-*(b+y)!=32&&*(b+x)-*(b+y)!=-32)
yesno=-1;}int main(){ char*a=&MAdam&; int x=palin(a); cout&&x; return 0;}
t;iostream&class Riqi{private: long nian,yue,public: Riqi(); Riqi(long Snian,long Syue,long Sri); void Set(long Snian,long Syue,long Sri); void Output();};Riqi::Riqi(){ nian=yue=ri=0;};Riqi::Riqi(long Snian,long Syue,long Sri){ Set(Snian,Syue,Sri);};void Riqi::Set(long Snian,long Syue,long Sri){ nian=S yue=S ri=S};void Riqi::Output(){ cout&&nian&&&年&&&yue&&&月&&&ri&&&日&&&};17.这里是代码。假设成员变量a,b为长整形。class A{protected:private:};class B:public A{};
您可能关注的推广
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁文档分类:
在线文档经过高度压缩,下载原文更清晰。
淘豆网网友近日为您收集整理了关于2015电大C++语言程序设计期末考试试题及答案小抄参考的文档,希望对您的工作和学习有所帮助。以下是文档介绍:2015电大C++语言程序设计期末考试试题及答案小抄参考 专业好文档1电大 C++语言程序设计期末考试试题及答案姓名____________ 学号____________ 班号___________题号一二(1) 二(2) 三总分成绩一、填空1.在类中必须声明成员函数的原型,成员函数的实现部分可以写在类外。2.如果需要在被调函数运行期间,改变主调函数中实参变量的值,则函数的形参应该是引用类型或指针类型。3. 抽象类只能作为基类使用,而不能声明它的对象。4.进行函数重载时,被重载的同名函数如果都没有用 const 修饰,则它们的形参个数或类型必须不同。5.通过一个常对象只能调用它的常成员函数,不能调用其他成员函数。6.函数的递归调用是指函数直接或间接地调用自身。7.拷贝构造函数的形参必须是本类对象的引用。二、阅读下列程序,写出其运行时的输出结果如果程序运行时会出现错误,请简要描述错误原因。1.请在以下两题中任选一题,该题得分即为本小题得分。如两题都答,则取两题得分之平均值为本小题得分。(1)程序:#include &iostream.h&#include &string(来源:淘豆网[/p-6638106.html]).h&class Base{ private:char msg[30];protected:public:Base(char s[],int m=0):n(m){ strcpy(msg,s);}void output(void){ cout&&n&&endl&&msg&&}};class Derived1:public Base{private:public:Derived1(int m=1):Base(&Base&,m-1){ n=m; }void output(void){ cout&&n&&Base::output();}};class Derived2:public Derived1{专业好文档2private:public:Derived2(int m=2):Derived1(m-1){ n=m; }void output(void(来源:淘豆网[/p-6638106.html])){ cout&&n&&Derived1::output();}};int main(){Base B(&Base Class&,1);Derived2 D;B.output();D.output();}运行结果:1Base Class210Base(2)程序:#include &iostream.h&class Samp{public:void Setij(int a,int b){i=a,j=b;}~Samp(){ cout&&&Destroying..&&&i&&}int GetMuti(){return i*j;}protected:};int main(){Samp *p;p=new Samp[5];if(!p){ cout&&&Allocation error\n&;return 1;}for(i(来源:淘豆网[/p-6638106.html])nt j=0;j&5;j++)p[j].Setij(j,j);for(int k=0;k&5;k++)cout&&&Muti[&&&k&&&] is:&&&p[k].GetMuti()&&delete[]p;return 0;}运行结果:Muti[0] is:0Muti[1] is:1Muti[2] is:4Muti[3] is:9Muti[4] is:16Destroying..4Destroying..3专业好文档3Destroying..2Destroying..1Destroying..02.请在以下两题中任选一题,该题得分即为本小题得分。如两题都答,则取两题得分之平均值为本小题得分。(1)程序:#include &iostream.h&#include &stdlib.h&class Vector{public:Vector(int s=1(来源:淘豆网[/p-6638106.html])00);int& Elem(int ndx);void Display(void);void Set(void);~Vector(void);protected:int *};Vector::Vector(int s){buffer=new int[size=s];}int& Vector::Elem(int ndx){if(ndx&0||ndx&=size){cout&&&error in index&&&exit(1);}return buffer[ndx];}void Vector::Display(void){for(int j=0; j& j++)cout&&Elem(j)&&}void Vector::Set(void){for(int j=0; j& j++)Elem(j)=j+1;}Vector::~(来源:淘豆网[/p-6638106.html])Vector(void){delete[]}int main(){Vector a(10);Vector b(a);a.Set();b.Display();}运行结果:123专业好文档最后出现错误信息,原因是:声明对象 b 是进行的是浅拷贝,b 与 a 共用同一个 buffer,程序结束前调用析构函数时对同一内存区进行了两次释放。(2)程序:#include&iostream.h&class CAT{public:CAT();CAT(const &CAT);~CAT();int GetAge(){ return *itsA }void SetAge( int age ){ *itsAge= }protected:int * itsA};CAT::CAT(){itsAge=*itsAge=5;}CAT::~CAT(){delete itsAitsAge=NULL;}int main(){CATc(来源:淘豆网[/p-6638106.html])out&&&a's age:&&&a.GetAge()&&a.SetAge(6);CAT b(a);cout&&&a's age:&&&a.GetAge()&&cout&&&b's age:&&&b.GetAge()&&a.SetAge(7);cout&&&a's age:&&&a.GetAge()&&cout&&&b's age:&&&b.GetAge()&&}运行结果:a's age:5a's age:6b's age:6a's age:7b's age:7最后出现错误信息,原因是:声明(来源:淘豆网[/p-6638106.html])对象 b 是进行的是浅拷贝,b 与 a 共用同一个 buffer,程序结束前调用析构函数时对同一内存区进行了两次释放。专业好文档- 5 -三、阅读下列程序及说明和注释信息,在方框中填写适当的程序段,使程序完成指定的功能程序功能说明:从键盘读入两个分别按由小到大次序排列的整数序列,每个序列 10 个整数,整数间以空白符分隔。用这两个序列分别构造两个单链表,每个链表有 10 个结点,结点的数据分别按由小到大次序排列。然后将两个链表合成为一个新的链表,新链表的结点数据仍然按由小到大次序排列。最后按次序输出合并后新链表各结点的数据。程序运行结果如下,带下划线部分表示输入内容,其余是输出内容:1 3 5 7 9 11 13 15 17 192 4 6 8 10 12 14 16 18 201 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20#include &iostream.h&#include &stdlib.h&//类定义部分(来源:淘豆网[/p-6638106.html])template &class T&class Node{private:Node&T& * //指向后继节点的指针public:T //数据域Node (const T& item, Node&T&* ptrnext = NULL); // 构造函数void InsertAfter(Node&T& *p); //在本节点之后插入一个同类节点 pNode&T& *DeleteAfter(void); //删除本节点的后继节点,返回其地址Node&T& *NextNode(void) // 获取后继节点的地址};template &class T&class LinkedList{private:Node&T& *front, * // 表头和表尾指针Node&T& *prevPtr, *currP //记录表当前遍历位置的指针,(来源:淘豆网[/p-6638106.html])由插入和删除操作更新 // 表中的元素个数 // 当前元素在表中的位置序号。由函数 Reset 使用Node&T& *GetNode(const T& item,Node&T& *ptrNext=NULL);// 生成新节点,数据域为 item,指针域为 ptrNextvoid FreeNode(Node&T& *p); //释放节点void CopyList(const LinkedList&T&& L); // 将链表 L 拷贝到当前表//(假设当前表为空)。被拷贝构造函数、operator=调用public:LinkedList(void); // 构造函数专业好文档- 6 -LinkedList(const LinkedList&T&& L); //拷贝构造函数~LinkedList(void); // 析构函数LinkedList&T&&(来源:淘豆网[/p-6638106.html]) operator= (const LinkedList&T&& L);//重载赋值运算符int ListSize(void) //返回链表中元素个数(size)int ListEmpty(void) //size 为 0 时返回 TRUE,否则返回 FALSEvoid Reset(int pos = 0); //将指针 currPtr 移动到序号为 pos 的节点,//prevPtr 相应移动,position 记录当前节点的序号void Next(void); //使 prevPtr 和 currPtr 移动到下一个节点int EndOfList(void) // currPtr 等于 NULL 时返回 TRUE, 否则返回 FALSEint CurrentPosition(void) //返回数据成员 positionvoid InsertFront(const T& item); //在表头插入一个数据域为 item 的节点void InsertRear(const T& item); //在表尾添加一个数据域为 item 的节点void InsertAt(const T& item); //在当前节点之前插入一个数据域为 item 的节点void InsertAfter(const T& item); //在当前节点之后插入一个数据域为 item 的节点T DeleteFront(void); //删除头节点,释放节点空间,更新 prevPtr、currPtr 和 sizevoid DeleteAt(void); //删除当前节点,释放节点空间,更新 prevPtr、currPtr 和 sizeT& Data(void); // 返回对当前节点成员 data 的引用void ClearList(void); // 清空链表:释放所有节点的内存空间。};//类实现部分略......template &class T&void MergeList(LinkedList&T&* la, LinkedList&T&* lb,LinkedList&T&* lc){//合并链表 la 和 lb,构成新链表 lc。//函数结束后,程序的数据所占内存空间总数不因此函数的运行而增加。while ( !la-&ListEmpty() &&!lb-&ListEmpty()){if (la-&Data()&=lb-&Data()){ lc-&InsertRear(la-&Data());la-&DeleteAt();}else{ lc-&InsertRear(lb-&Data());lb-&DeleteAt();}}专业好文档- 7 -while ( !la-&ListEmpty() ){lc-&InsertRear(la-&Data());la-&DeleteAt();}while ( !lb-&ListEmpty() ){lc-&InsertRear(lb-&Data());lb-&DeleteAt();}}int main(){LinkedList&int& la, lb,int item,//读如数据建立链表 lafor (i=0;i & 10;i++){cin&&la.InsertRear(item);}la.Reset();//读如数据建立链表 lbfor (i=0;i & 10;i++){cin&&lb.InsertRear(item);}lb.Reset();MergeList(&la, &lb, &lc);//合并链表lc.Reset();// 输出各节点数据,直到链表尾while(!lc.EndOfList()){cout &&lc.Data() && & &;lc.Next(); // 使 currPtr 指向下一个节点}cout &&}专业好文档- 8 -请您删除一下内容,O(∩_∩)O 谢谢!!!Many people have the same mixed feelings when planning a trip during Golden Week. With heaps of time, theseven-day Chinese 请您删除一下内容,O(∩_∩)O 谢谢!!!National Day holiday could be the best occasion to enjoy a destination. However, it can also bethe easiest way to ruin how you feel about a place and you may e more fatigued after the holiday, due to battling the large crowds. During peak season,a dream about a place can turn to nightmare without careful planning, especially if you travel with children and older people. As mostChinese people will take the holiday to visit domestic tourist destinations, crowds andbusy traffic are inevitable at most places. Also to be expected are increasing transport modation prices, with the possibility that there will be no rooms available. It is mon that you' ll wait in the line for one hour to get a ticket, and another two hours at the site,to only see a tiny bit of the place due to the crowds. Last year, 428 million tourists traveled in China over theweek-long holiday in October. Traveling during this period is a matter that needs thorough preparation. If you are short ontime to plan the ing &Golden Week& it may not be a bad idea to avoid some of the most crowded places for now.There is always a place so fascinating that everyone yearns for. Arxan is a placelike this. The beauty of Arxan is everlasting regardless of the changing of four seasons.Bestowed by nature, its spectacular seasonal landscape and mountains are just beyond word. Arxan is a crucialdestination for the mended travelling route, &China Inner Mongolia Arxan — Hailar — Manzhouli&. It isalso the joint of the four prairies across the Sino-Mongolian border, where people gravitate towards the exotic atmospheremixed with Chinese, Russian, and Mongolia elements. As a historic site for the Yitian Battle, Arxan still embodies the spiritof Genghis Khan. Walking into Arxan, you will be amazed by a kaleidoscope of gorgeous colors all the year round -- theSpring azaleas blooming red in the snow, the Summer sea wavering blue in the breeze, the Autumn leaves painted inyellow covering volcanic traces, and the Winter woods shining white on the vast alpine snowscape. Hinggan League Arxancity is situated in the far eastern area of Inner Mongolia Autonomous Region. Its full name &Haren Arxan& means &hot holy water& in the Mongolian language.Arxan is a tourism city in the northern frontier with a blend of large forest, grand prairies, vast snowfield, heaven lake cluster, thermium, as well as luster. It is a rare and unique ecotourism base filled with healthy sunshine, clean air and unspoiled green. Nestled close to the country's largest virgin forest,and known for its spring and ecological environment, Arxan is marveled at by many tourists as thepurest land on earth. You cannot miss out the Autumn of Arxan. It is definitely the best withbrightly-colored scenery full of emotions. Autumn in the northern part of the es earlierthan the South. A September rain followed by the footprints of Autumn brings more colors to theonce emerald green mountain and blooming grassland. Shutterbugs flock to see for themselves themarvel of splendid colors around the mountains and waters, many of whom have travel a longdistance and even camp here only to capture a moment of the nature wonder. The silver birchturns golden, while the larch is still proudly green. You will find yourself drowned in theintoxicating red of the wild fruits as well as the glamour of flowers in full blown. And your heart willbe lingering on the woods as it's time for the wild fruits to ripe. The picturesque Arxan inAutumn is indeed a fairyland only exists in a dream that satisfies all your fantasies. If it rains heavilyon Saturday night, some elderly Chinese will say it is because Zhinu, or the Weaving Maid, iscrying on the day she met her husband Niulang, or the Cowherd, on the Milky Way. Most Chineseremember being told this romantic tragedy when they were children on Qixi, or the Seventh NightFestival, which falls on the seventh day of the seventh lunar month, which is usually in early August.This year it falls on Saturday, August 2. Folklore Story As the story goes, once there was a cowherd,Niulang, who lived with his elder brother and sister-in-law. But she disliked and abused him, and the boy was forced to leave home with only an old cow pany. The cow, however, was a former god who had violated imperial rules and was sent to earth in bovine form. One day the cow led Niulang to a lakewhere fairies took a bath on earth. Among them was Zhinu, the most beautiful fairy and a skilled seamstress. The two fell in love at first sight and were soonmarried. They had a son and daughter and their happy life was held up as an example for hundreds of years in China. Yet in the eyes of the Jade Emperor, theSupreme Deity in Taoism, marriage between a mortal and fairy was strictly forbidden. He ordered the heaven troop to catch Zhinu back. Niulang grewdesperate when he discovered Zhinu had been taken back to heaven. Driven by Niulang's misery, the cow told him to turn its hide into a pair of shoes after itdied. The magic shoes whisked Niulang, who carried his two children in baskets strung from a shoulder pole, off on a chase after the empress. The pursuitenraged the empress, who took her hairpin and slashed it across the sky creating the Milky Way which separated husband from wife. But all was not lost asmagpies, moved by their love and devotion, formed a bridge across the Milky Way to reunite the family. Even the Jade Emperor was touched, and allowedNiulang and Zhinu to meet once a year on the seventh night of the seventh month. This is how Qixi came to be. The festival can be traced back to the HanDynasty (206 BC-AD 220). Traditionally, people would look up at the sky and find a bright star in the constellation Aquila as well as the star Vega, which areidentified as Niulang and Zhinu. The two stars shine on opposite sides of the Milky Way. Customs In bygone days, Qixi was not only a special day for lovers,but also for girls. It is also known as the &Begging for Skills Festival& or &Daughters' Festival.& In this day, girls will throw a sewing needle into a bowl full ofwater on the night of Qixi as a test of embroidery skills. If the needle floats on top of the water instead of sinking, it proves the girl is a skilled embroiders. Singlewomen also pray for finding a good husband in the future. And the newly married women pray to e pregnant quickly. Tradition transformed The lovestory of Niulang and Zhinu, and the Qixi Festival have been handed down for generations. Yet these ancient traditions and customs are slowly dying out. Manymodern Chinese, particularly youngsters, seem to know more about St Valentine's Day on February 14, characterized by bouquets of roses, chocolates andromantic candlelight dinners, than they do about their home-grown day for lovers. Even Qixi is nowadays referred to as the &Chinese Valentine's Day.& Moreand more young Chinese people begin to celebrate this day in a very similar way as that in western countries. Fewer people than ever will gaze at the heavenson Saturday to pick out the two stars shining bright on either side of the Milky Way, that is, if people even know on which day Qixi falls. There are readyreminders dotted about, in the form of big ads saying &Sales on Chinese Valentine's Day!& in shops, hotels and restaurants. But few young women will markthe festival with their boyfriends, or take part in traditional activities to pray for cleverness.播放器加载中,请稍候...
该用户其他文档
下载所得到的文件列表2015电大C++语言程序设计期末考试试题及答案小抄参考.doc
文档介绍:
2015电大C++语言程序设计期末考试试题及答案小抄参考 专业好文档1电大 C++语言程序设计期末考试试题及答案姓名____________ 学号____________ 班号___________题号一二(1) 二(2) 三总分成绩一、填空1.在类中必须声明成员函数的原型,成员函数的实现部分可以写在类外。2.如果需要在被调函数运行期间,改变主调函数中实参变量的...
内容来自淘豆网转载请标明出处.

我要回帖

更多关于 cout输出十六进制 的文章

 

随机推荐