面向对象程序设计的问题,求助各位高手,一下这些程序运行结果,谢谢大家了!感激 10
1.#include<iostream.h>#include<string.h>voidmain(){char*a[5]={"student","worker","cad...
1.#include<iostream.h>
#include<string.h>
void main(){
char *a[5]={"student","worker","cader","soldier","peasant"};
char *p1,*p2;
p1=p2=a[0];
for (int i=0; i<5; i++){
if (strcmp(a[i],p1)>0) p1=a[i];
if (strcmp(a[i],p2)< 0) p2=a[i];
}
cout<<p1<<' '<<p2<<end1;
}
2# include<iostream.h>
int a=5;
void main(){
int a=10,b=20;
cout<<a<<' '<<b<<end1;
{ int a=0,b=0;
for (int i=1; i<6;i++){
a+=i;b+=a;
}
cout<<a<<' '<<b<<' '<<::a<<end1;
}
cout<<a<<' '<<b<<end1;
}
3.#include <iomanip.h>
int LB(int *a,int n){
int s=1;
for (int i=0; i<n; i++)
s*=*a++;
return s;
}
void main(){
int a[]={1,2,3,4,5,6,7,8};
int b=LB(a,5)+LB(&a[3],3);
cout<<"b="<<b<<end1;
}
4#include<iomanip.h>
woid main()
{
int a[9]={2,4,6,8,10,12,14,16,18};
for (int i=0;i<9;i++){
cout<<setw(5)<<*(a+i);
if ((i+1)%3==0) cout<<end1;}
}
5#include <iostream.h>
void main() {
char a[]="abcdabcabfgacd"
int i1=0,i2=0,i=0;
while (a[i]){
if (a[i]=='a') i1++;
if (a[i]=='b') i2++;
i++; }
cout<<i1<<' '<<i2<<end1;
}
6.#include<iostream.h>
class Sample
{
int x;
public;
Sample(int a)
{
x=a;
cout<<"constructing object: x="<<x<<end1;
}
};
void func(int n)
{
Sample obj(n);
}
int main()
{
func(1);
func(10);
} 展开
#include<string.h>
void main(){
char *a[5]={"student","worker","cader","soldier","peasant"};
char *p1,*p2;
p1=p2=a[0];
for (int i=0; i<5; i++){
if (strcmp(a[i],p1)>0) p1=a[i];
if (strcmp(a[i],p2)< 0) p2=a[i];
}
cout<<p1<<' '<<p2<<end1;
}
2# include<iostream.h>
int a=5;
void main(){
int a=10,b=20;
cout<<a<<' '<<b<<end1;
{ int a=0,b=0;
for (int i=1; i<6;i++){
a+=i;b+=a;
}
cout<<a<<' '<<b<<' '<<::a<<end1;
}
cout<<a<<' '<<b<<end1;
}
3.#include <iomanip.h>
int LB(int *a,int n){
int s=1;
for (int i=0; i<n; i++)
s*=*a++;
return s;
}
void main(){
int a[]={1,2,3,4,5,6,7,8};
int b=LB(a,5)+LB(&a[3],3);
cout<<"b="<<b<<end1;
}
4#include<iomanip.h>
woid main()
{
int a[9]={2,4,6,8,10,12,14,16,18};
for (int i=0;i<9;i++){
cout<<setw(5)<<*(a+i);
if ((i+1)%3==0) cout<<end1;}
}
5#include <iostream.h>
void main() {
char a[]="abcdabcabfgacd"
int i1=0,i2=0,i=0;
while (a[i]){
if (a[i]=='a') i1++;
if (a[i]=='b') i2++;
i++; }
cout<<i1<<' '<<i2<<end1;
}
6.#include<iostream.h>
class Sample
{
int x;
public;
Sample(int a)
{
x=a;
cout<<"constructing object: x="<<x<<end1;
}
};
void func(int n)
{
Sample obj(n);
}
int main()
{
func(1);
func(10);
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询