一道c++编程问题,求大神打出代码,悬赏全给你
#include #include using namespace std;class Human {public: string name; string sex; int old; Human() {} ~Human() {} string getName(); void setName(string name); string getSex(); void setSex(string sex); int getOld(); void setOld(int old);};class Teacher : virtual public Human {public: int numberx; Teacher() {} ~Teacher() {} string getName() { return this->name; } void setName(string name) { this->name = name; } string getSex() { return this->sex; } void setSex(string sex) { this->sex = sex; } int getOld() { return this->old; } void setOld(int old) { this->old = old; } int getNumberX() { return this->numberx; } void setNumberX(int numberx) { this->numberx = numberx; } string getJob() { return this->job; } void setJob(string job) { this->job = job; } double getSalery() { return this->salery; } void setSalery(double salery) { this->salery = salery; }private: string job; double salery;};class Student : virtual public Human {public: int number; string Class; string profession; int admission; Student() {} ~Student() {} string getName() { return this->name; } void setName(string name) { this->name = name; } string getSex() { return this->sex; } void setSex(string sex) { this->sex = sex; } int getOld() { return this->old; } void setOld(int old) { this->old = old; } int getNumber() { return this->number; } void setNumber(int number) { this->number = number; } string getClass() { return this->Class; } void setClass(string Class) { this->Class = Class; } string getProfession() { return this->profession; } void setProfession(string profession) { this->profession = profession; } int getAdmission() { return this->admission; } void setAdmission(int admission) { this->admission = admission; }};class Postgradute : public Teacher, public Student {public: string company; string getName() { return this->name; } void setName(string name) { this->name = name; } string getSex() { return this->sex; } void setSex(string sex) { this->sex = sex; } int getOld() { return this->old; } void setOld(int old) { this->old = old; } Postgradute() {} ~Postgradute() {} string getCompany() { return this->company; } void setCompany(string company) { this->company = company; }};class StuTeacher : public Teacher, public Student {public: StuTeacher() {} ~StuTeacher(){}};void main(){ Postgradute pg = Postgradute(); pg.setName("test"); pg.setAdmission(88); pg.setClass("two"); pg.setCompany("DUT"); pg.setJob("HelpTeacher"); pg.setOld(18); pg.setProfession("software"); pg.setSalery(1000); pg.setSex("boy"); pg.setNumber(10192582); pg.setNumberX(201193247); cout << pg.getName() << endl << pg.getAdmission() << endl << pg.getCompany() << endl << pg.getJob() << endl << pg.getNumber() << endl << pg.getNumberX() << endl << pg.getOld() << endl << pg.getProfession() << endl << pg.getSalery() << endl << pg.getSex() << endl;}
现作的, 有bug的话站内短信我
要处理的文件必须先改成英文名( 只含ASCII的名字 )
fstream不能直接打开中文名文件, 而setlcale和locale::global也会造成不能显示或报错( 网上的方法和我自己尝试都不行 ), 我也不想用c或api来代替, 只能凑合一下了; 或者你自己改下代码, 用其他文件打开方式
#include
#include
#include
#include
using namespace std;
class FileWordReplacer
{
protected:
static FileWordReplacer *singleInstance;
ifstream fileIn;
ofstream fileOut;
FileWordReplacer(){}
string& StringReplace( string &szSentence, string wordOld, string wordNew ) const;
string& StringReplaceEx( string &szSentence, string wordOld, string wordNew ) const;
string& StringToUper( string &szSource ) const;
public:
static FileWordReplacer* GetInstance()
{
if( NULL == singleInstance )
return singleInstance = new FileWordReplacer;
return singleInstance;
}
bool FileReplace( string szFileName, string wordOld, string wordNew, bool bDiv );
};
bool FileWordReplacer::FileReplace( string szFileName, string wordOld, string wordNew, bool bDiv )
{
fileIn.rdbuf()->open( szFileName.c_str(), ios::in );
if( !fileIn.is_open() )
{
cerr << "File does'nt exist." << endl;
return false;
}
fileOut.rdbuf()->open( (szFileName "_").c_str(), ios::out );
string szRead;
while( getline( fileIn, szRead ) )
fileOut
<< (bDiv ? StringReplace( szRead, wordOld, wordNew ) : StringReplaceEx( szRead, wordOld, wordNew ) )
<< endl;
fileIn.rdbuf()->close();
fileOut.rdbuf()->close();
string szCmd = "del " szFileName;
system( szCmd.c_str() );
szCmd = "ren " szFileName "_ ";
size_t nPos = szFileName.find_last_of('\\') 1;
szCmd = szFileName.substr( nPos, szFileName.size() - nPos );
system( szCmd.c_str() );
return true;
}
string& FileWordReplacer::StringReplace( string &szSentence, string wordOld, string wordNew ) const
{
size_t nPos = 0;
while( string::npos != (nPos = szSentence.find( wordOld, nPos)) )
{
szSentence.replace( nPos, wordOld.size(), wordNew );
nPos = wordNew.size();
}
return szSentence;
}
string& FileWordReplacer::StringReplaceEx( string &szSentence, string wordOld, string wordNew ) const
{
string szUper = szSentence;
StringToUper( szUper );
string wordUper = wordOld;
StringToUper( wordUper );
const size_t nDef = wordNew.size() - wordOld.size();
size_t nPos = 0;
int nTimes = 0;
while( string::npos != (nPos = szUper.find( wordUper, nPos)) )
{
szSentence.replace( nPos nDef * nTimes, wordOld.size(), wordNew );
nPos = wordUper.size();
nTimes ;
}
return szSentence;
}
string& FileWordReplacer::StringToUper( string &szSource ) const
{
string::iterator it = szSource.begin();
while( szSource.end() != it )
{
if( islower( *it ) )
*it = toupper( *it );
it ;
}
return szSource;
}
FileWordReplacer* FileWordReplacer::singleInstance = NULL;
int main()
{
string szFileName;
cout << "输入文件名 : (可以是绝对路径或相对路径)" << endl;
cin >> szFileName;
string wordOld, wordNew;
cout << "输入想要替换的单词 :" << endl;
cin >> wordOld;
cout << "输入新的单词:" << endl;
cin >> wordNew;
bool bDiv;
while( true )
{
cout << "区分大小写? (Y/N)" << endl;
char c;
cin >> c;
if( 'y' == c || 'Y' == c )
{
bDiv = true;
break;
}
else if( 'n' == c || 'N' == c )
{
bDiv = false;
break;
}
}
if ( FileWordReplacer::GetInstance()->FileReplace( szFileName, wordOld, wordNew, bDiv ) )
cout << "
替换成功" << endl;
return 0;
}
c语言的, 这个可以用中文文件名
#include
#include
#include
#include
#define TRUE 1
#define FALSE 0
#define NULL 0
#define EOF (-1)
#define BUFFER_SIZE 4 * 1024 //当文件单行超过1k字节时, 增加该值, 是 4 * 最大行长
typedef int BOOL;
typedef struct tagWORD
{
char szValue[256];
int nLength;
}WORD, *PWORD;
typedef struct tagSENTENCE
{
char *szValue;
int nLength;
}SENTENCE, *PSENTENCE;
// 从用户处获取文件名
void GetFileName( char *szFileName );
// 从用户处获取新旧两句单词(短语)
void GetPairWord( PWORD pWordOld, PWORD pWordNew );
// 从用户处咨询是否区分大小写
BOOL IsDiv();
// 将指定文件中的旧单词替换为新单词, 以bDiv为是否区分大小写的标志
void FileWordReplace( const char *szFileName, PWORD pWordOld, PWORD pWordNew, BOOL bDiv );
int main()
{
char szFileName[64];
WORD wordOld, wordNew;
BOOL bDiv;
//用户输入文件名
GetFileName( szFileName );
//用户输入新旧单词
GetPairWord( &wordOld, &wordNew );
//询问用户是否区分大小写
bDiv = IsDiv();
//替换文件内容
FileWordReplace( szFileName, &wordOld, &wordNew, bDiv );
return 0;
}
//从文件中读取一行句子
int ReadSentence( FILE *pFile, PSENTENCE pSentence )
{
char szFormat[20] = {0};
szFormat[0] = '%';
sprintf( szFormat 1, "%d[^
]", BUFFER_SIZE / 4 - 1 );
memset( pSentence->szValue, 0, BUFFER_SIZE );
fscanf( pFile, szFormat, pSentence->szValue );
pSentence->nLength = (int)strlen( pSentence->szValue );
return fgetc( pFile ) * !pSentence->nLength;
}
//将一条句子写进文件中
int WriteSentence( FILE *pFile, PSENTENCE pSentence )
{
int nWrited;
nWrited = (int)fwrite( pSentence->szValue, sizeof(char), pSentence->nLength, pFile );
fputc( '
', pFile );
return nWrited 1;
}
//判断一个字母是否是小写
BOOL IsLower( char c )
{
return c >= 'a' && c <= 'z' ;
}
//将一个字符转化为大写
char ToUper( char c )
{
return c - 'a' 'A';
}
//用一条一般句子生成一条不含小写字母的句子
char* MakeUper( const char *szSource, const int nLength )
{
char *szTemp = (char*)malloc( sizeof(char) * BUFFER_SIZE );
int i;
for( i=0; i<nLength; i )
szTemp[i] = IsLower( szSource[i] ) ? ToUper( szSource[i] ) : szSource[i];
szTemp[i] = 0;
return szTemp;
}
//将句子中的单词(短语)替换成新单词, 区分大小写
int StringWordReplace( PSENTENCE pSentence, PWORD pWordOld, PWORD pWordNew )
{
char *szTemp = (char*)malloc( sizeof(char) * BUFFER_SIZE );
int nPos = 0, nTimes = 0;
const int nDif = pWordNew->nLength - pWordOld->nLength;
while( nPos nLength - pWordOld->nLength )
{
if( !strncmp( pSentence->szValue nPos, pWordOld->szValue, pWordOld->nLength ) )
{
strcpy( szTemp nPos nTimes * nDif, pWordNew->szValue );
nPos = pWordOld->nLength;
nTimes ;
}
else
{
szTemp[nPos nTimes * nDif] = pSentence->szValue[nPos];
nPos ;
}
}
strcpy( szTemp nPos nTimes * nDif, pSentence->szValue nPos );
pSentence->nLength = nDif * nTimes;
free( pSentence->szValue );
pSentence->szValue = szTemp;
return nTimes;
}
//将句子中的单词(短语)替换成新单词, 不区分大小写
int StringWordReplaceEx( PSENTENCE pSentence, PWORD pWordOld, PWORD pWordNew )
{
char *szTemp = (char*)malloc( sizeof(char) * BUFFER_SIZE );
char *szUperSentence = MakeUper( pSentence->szValue, pSentence->nLength );
char *szUperWord = MakeUper( pWordOld->szValue, pWordOld->nLength );
int nPos = 0, nTimes = 0;
const int nDif = pWordNew->nLength - pWordOld->nLength;
while( nPos nLength - pWordOld->nLength )
{
if( !strncmp( szUperSentence nPos, szUperWord, pWordOld->nLength ) )
{
strcpy( szTemp nPos nTimes * nDif, pWordNew->szValue );
nPos = pWordOld->nLength;
nTimes ;
}
else
{
szTemp[nPos nTimes * nDif] = pSentence->szValue[nPos];
nPos ;
}
}
strcpy( szTemp nPos nTimes * nDif, pSentence->szValue nPos );
free( szUperSentence );
free( szUperWord );
pSentence->nLength = nDif * nTimes;
free( pSentence->szValue );
pSentence->szValue = szTemp;
return nTimes;
}
//从用户那里获取一个单词
void GetWord( PWORD pWord )
{
memset( pWord->szValue, 0, 256 );
puts("输入单词(可以是中间有空格的短语), 但不能超过255个字符");
scanf("%5[^
]", pWord->szValue );
fflush( stdin );
pWord->nLength = strlen( pWord->szValue );
}
//将旧文件删除, 将新文件改成旧文件的名字
//因为文件中单词替换后文件长度可能改变, 所以只能生成新文件再删除旧的
void DelAndReNameFile( const char *szFileName, const char *szTempFileName )
{
char szCmd[128] = {0};
const char *pCTemp;
strcpy( szCmd, "del ");
strcpy( szCmd 4, szFileName );
system( szCmd );
memset( szCmd, 0, 128 );
strcpy( szCmd, "ren ");
strcpy( szCmd 4, szTempFileName );
szCmd[strlen(szCmd)] = ' ';
pCTemp = strrchr( szFileName, '\\' );
strcpy( szCmd strlen(szCmd), pCTemp ? (pCTemp 1) : szFileName );
system( szCmd );
}
//在旧文件相同的路径下给新文件取名, 文件名是某单词的md5码
void GetTempFileName( const char *szFileName, char *szTempFileName )
{
const char *pCTemp;
pCTemp = strrchr( szFileName, '\\' );
if( pCTemp )
strncpy( szTempFileName, szFileName, pCTemp - szFileName 1 );
strcpy( szTempFileName strlen(szTempFileName), "22EFDBE132EABC102306BD7A334FB434" );
}
//以下几个函数的说明在声明处
void FileWordReplace( const char *szFileName, PWORD pWordOld, PWORD pWordNew, BOOL bDiv )
{
FILE *pFileS, *pFileD;
char szTempFileName[128] = {0};
SENTENCE sentence;
GetTempFileName( szFileName, szTempFileName );
sentence.szValue = (char*)malloc( sizeof(char) * BUFFER_SIZE );
pFileS = fopen( szFileName, "r" );
pFileD = fopen( szTempFileName, "w" );
while( EOF != ReadSentence( pFileS, &sentence ) )
{
if( bDiv )
StringWordReplace( &sentence, pWordOld, pWordNew );
else
StringWordReplaceEx( &sentence, pWordOld, pWordNew );
WriteSentence( pFileD, &sentence );
}
fclose( pFileS );
fclose( pFileD );
free( sentence.szValue );
DelAndReNameFile( szFileName, szTempFileName );
}
void GetPairWord( PWORD pWordOld, PWORD pWordNew )
{
puts("输入要替换的单词 : ");
GetWord( pWordOld );
puts("输入新的单词 : ");
GetWord( pWordNew );
}
BOOL IsDiv()
{
char cInput;
while( TRUE )
{
puts("区分大小写吗? (Y/N)");
cInput = getchar();
if( 'y' == cInput || 'Y' == cInput )
return TRUE;
else if( 'n' == cInput || 'N' == cInput )
return FALSE;
}
}
void GetFileName( char *szFileName )
{
FILE *pFile;
szFileName[63] = 0;
while( TRUE )
{
puts("输入文件名");
if ( 1 == scanf( "cs", szFileName ) )
{
fflush( stdin );
if( pFile = fopen( szFileName, "r" ) )
{
fclose( pFile );
break;
}
else
puts("找不到文件");
}
}
}
最后一种方法, 去除了校验等...
#include
#include
// 缓冲区, 用来放读取的内容
#define BUFFER_SIZE 1024
// 部分大小写的字符串比较
int MyCmp( const char *sz1, const char *sz2, int nLen )
{
char cMax, cMin;
for( ;nLen--; sz1 , sz2 )
{
if( *sz1 == *sz2 )
continue;
cMax = *sz1 >= *sz2 ? *sz1 : *sz2;
cMin = *sz1 *sz2 - cMax;
if( (cMax = 'a') && (32 == cMax - cMin) )
continue;
return *sz1 - *sz2;
}
return 0;
}
int main()
{
// 文件指针
FILE *pFileS, *pFileD;
// 输入缓冲; 要替换的单词; 新的单词
char buffer[BUFFER_SIZE], wordOld[64] = {0}, wordNew[64] = {0};
// 缓冲区实际大小; 缓冲区操作标志; 每次读取的字节数; 要替换的单词长度; 新单词的长度; 区分大小写标志
int nTop = 0, nPoint, nRead, nOldLen, nNewLen, bDiv;
puts("输入两个词");
scanf("cscs", wordOld, wordNew);
nOldLen = strlen(wordOld), nNewLen = strlen(wordNew);
puts("是否区分大小写? 输入1(Yes),0(No)");
scanf("%d", &bDiv);
pFileS = fopen("a.txt", "rb");
pFileD = fopen("aa.txt", "wb");
while( nRead = fread( buffer nTop, sizeof(char), BUFFER_SIZE - nTop, pFileS) )
{
nTop = nRead;
// 处理旧单词整数倍的那部分缓冲
for( nPoint=0; nPoint<=nTop - nOldLen; )
{
// 如果要区分则用memcmp比较, 不区分用自定义比较函数比较
if( !( bDiv ? memcmp( buffer nPoint, wordOld, nOldLen) : MyCmp( buffer nPoint, wordOld, nOldLen )) )
{
// 相等, 写进文件
fwrite( wordNew, sizeof(char), nNewLen, pFileD );
// 缓冲区标志(相当于指针)移位
nPoint = nOldLen;
}
else
// 不相等, 将该字节写入并移动1字节
fputc( buffer[nPoint ], pFileD );
}
// 处理剩下的缓冲区; 方法同上
if( !( bDiv ? memcmp( buffer nPoint, wordOld, nTop - nPoint ) : MyCmp( buffer nPoint, wordOld, nTop - nPoint)) )
{
memcpy( buffer, buffer nPoint, nTop - nPoint );
nTop = nTop - nPoint;
}
else
{
fwrite( buffer nPoint, sizeof(char), nTop - nPoint, pFileD );
nTop = 0;
}
}
// 关闭文件
puts("转化成功");
fclose( pFileS ), fclose( pFileD );
return 0;
}{[MIMIcall]]网络电话软件
写了1个小时,哈哈哈哈,代码仅供参考~需要注意这里,0年1月1日为第一天,满足题意“”将指定日期转换成从0年O月O日起的天数“”,里面有一些C ++11的特性(右值引用需要提前了解一下哈)~
#include <iostream>
using namespace std;
class Date{
public:
Date(int y = 0, int m = 0, int d = 0) :m_year(y), m_month(m), m_day(d){};
int getYear(){
return m_year;
}
int getMonth(){
return m_month;
}
int getDay(){
return m_day;
}
Date operator+(int days){
//返回某日期加上天数得到的日期
int firstdays = dton(*this);
return ntod(firstdays + days);
}
Date operator-(int days){
//返回某日期减去天数得到的日期
int firstdays = dton(*this);
if(firstdays - days > 0){
return ntod(firstdays - days);
}
else{
return Date(0,0,0);//对于不合法的天数都返回为000;
}
}
int operator-(Date&b){
//返回两日期相差的天数
int firstdays = dton(*this);
int seconddays = dton(b);
return firstdays - seconddays;
}
friend ostream& operator << (ostream &out, Date &a){
cout << a.m_year << " 年" << a.m_month << " 月" << a.m_day << " 日";
return out;
}
friend ostream& operator << (ostream &out, Date &&a){
cout << a.m_year << " 年" << a.m_month << " 月" << a.m_day << " 日";
return out;
}
protected:
bool leap(int year){
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
return true;
return false;
}
int dton(Date &b){
//将指定日期转换成从0年O月O日起的天数
int sum = 0;
for (int i = 0; i < b.m_year; i++){
if (leap(i)){
sum += 366;
}
else
sum += 365;
}
bool flag = leap(b.m_year);
for (int i = 0; i < b.m_month - 1; i++)
sum += day_tab[flag][i];
sum += b.m_day;
return sum;
}
Date ntod(int day){
//将指定的0年1月1日起的天数转换成对应的日期
int year = 0;
while (day > 365){
if (leap(year))
day -= 366;
else
day -= 365;
year++;
}
int i = 0;
bool flag = leap(year);
int monthday = 0;
for (i = 0; i < 12 && monthday <= day; i++){
monthday += day_tab[flag][i];
}
monthday -= day_tab[flag][i - 1];
i--;
Date *a = NULL;
if(day -monthday !=0)
a = new Date(year, i + 1, day - monthday);
else{
if (i != 0)
a = new Date(year, i, day_tab[flag][i]);
else
a = new Date(year-1, 12, 31);
}
return *a;
}
int day_tab[2][12] = { // day_tab二维数组存放各月天数,第一行对应非闰年,第二行对应闰年
{ 31, 28, 31, 30, 3l, 30, 3l, 3l, 30, 31, 30, 31 },
{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, }
};
private:
int m_year;
int m_month;
int m_day;
};
int main(){
Date a(0, 12, 31);
cout << a << endl;
cout << a + 1 << endl;
Date b = a-2;
cout<<b<<endl;
}
求C语言编程题
求大量C语言编程题,最好附上代码我要的是有解释的,有思路,最好跟书上的解答一样... 求大量C语言编程题,最好附上代码我要的是有解释的,有思路,最...三、指出下列程序中导致不能出现预期结果的唯一错误(不考虑编程规范错误)1.下面程序用于输出用户输入的字符串。请指出其中的问题#define OK 0#define ERR ...
C++ 编程问题、求大神解答
第一题:#include<iostream> include<cstdlib> using namespace std;int main(){ double a,b,c,s,v;cout<<"请输入立方体的三条边长,用空格隔开,按ENTER键结束输入:";cin>>a>>b>>c;s=2*(a*b+a*c+b*c);v=a*b*c;cout<<"立方体的三条边为:a="<<a<<" "<<"b="<<b<<" ...
C语言编程问题?
思路:1、利用ftell函数获取文件的长度(字节数)。2、利用fread函数读取文件所有内容。3、通过遍历字符串,进行大小写判断及转换。下面是演示代码:(命令符不想输入,连续两次回车)include <stdio.h> include <malloc.h> include <string.h> define FPH "C:\\\\test.txt"long getFileSize(char path...
C语言的简单编程问题,希望大哥大姐指点,万分感谢
一、计算机中的整数是用补码来表示的 (补码是什么?请查询相关资料)二、C中的整型常量默认为int类型,int类型是一个有符号类型(有符号类型和无符号类型请查询相关资料)三、char类型数据在计算机中占一个字节,int类型占4个字节,char类型是一个有符号类型 四、197在计算机中存放的二进制码为:0000....
C语言编程问题,初学者,麻烦简单些,谢谢(*°∀°)=3?
include "stdio.h"int main(){ int sex,height;float weight,bzweight;\/\/输入体重和标准体重 printf("输入性别(0-男性,1-女性):");scanf("%d",&sex);printf("输入身高(cm):");scanf("%d",&height);printf("输入体重(kg):");scanf("%f",&weight);if(sex==0)bzweight=(height-...
c编程问题
那b=(a++)+(a++);也就是b=(1+1)+(1+1)就是b=2 了,所以输出结果是2 了!!!“(二)”里面你赋给a的值是0;那那b=(a++)+(a++);也就是b=0+0 就是b=0 了,所以输出结果当然是 了!!!很简单的道理哈~~够详细了,懂了吧!!!呵呵~~我最近也刚开始学C!楼上的,...
一个c\/c++的编程问题
printf(" 学号\\t 姓名 性别 英语成绩 数学成绩 C语言成绩 总分 平均分\\n"); } void printe(Node *p)\/* 本函数用于输出英文 *\/ { printf("%-12s%s\\t%s\\t%d\\t%d\\t%d\\t %d\\t %d\\n",p->data.num,p->data.name,p->data.sex,p->data.egrade,p->data.mgrade,p->data.cgrade,p->data....
一道C编程问题
这是个有点麻烦的动态规划问题 首先给每块砖的长宽高都排个序,使得xi>=yi>=zi,省得之后还要写一大堆if 假设最底下的砖的底面的长和宽分别为a和b(a>=b)的时候,所能够搭出的石塔的最大高度为f(a,b)那么可以得到状态转移方程 f(a,b)=max {0,f(xi,yi)+zi(xi<a && yi<b时)f(yi...
C语言的简单编程问题 有没有人能帮我看看我编的错在哪了?
错误在于这一句:if (p[i+j]!='*') a[i++]=p[i+j]事实上,用于对数组a顺序写入字符的下标i,和对数组p遍历使用的下标i+j 两者不应该相互影响,而你的程序中,却对i做了自增,导致后面的p[i+j]没有正常的挨个遍历,而是跳过了一些字符。正确的做法是应该对数组a的处理另外使用一个下标...
非常头疼的C语言编程问题!!!
考虑到篇幅问题与难度关系,笔者仅就比较基本的单向链表给出机械工业出版社《C程序设计教程》(第二版)中的源程序。我不推荐初学者过早接触数据结构,因为其中涉及了二级指针和自引用结构的大量应用,在打牢基础之前基本不可能完全读懂程序就更不要说运用了。对数据结构有兴趣的同学可以再和我进行交流。 五、学习指针与...
危羽倍洁: #include<iostream>using namespace std;void Converse(char *s, int len){ for(int i=0;i<len;i++){ if(s[i]>='a' && s[i]<='z') s[i] -= 32; }}void copy(char*a, char*b){ int i=0; while(a[i] !='\0'){ b[i]=a[i]; i++; } b[i]='\0';}void Connect(char*a, char*b){ int len = 0; while...
元氏县19415586670: 求C++编程大神从键盘输入两个两位数a、b,将其组合成一个四位数输出(千位是a的个位,百位是b的十位,十位是b的个位,个位是a的十位) - ?
危羽倍洁:[答案] 不想敲代码了,主要的给你说一下. a的个位是 a % 10 a的十位是 a / 10 因为b的十位占用了输出的数的百位,个位占用了输出的数的十位,所以b * 10就可以满足要求了. 所以最后输出的数 Ans = a % 10 * 1000 + b * 10 + a / 10;代码里核心就是这一句...
元氏县19415586670: 急求一道C++编程题代码,求大神解决!!!!!!?
危羽倍洁: /* 9 10 11 19 20 23 31 34 35 39 42 43 45 49 54 62 65 87 88 89 Press any key to continue */ #include <stdio.h> void Sort(int a[],int n) { int i,j,k,t; for(i = 0; i < n - 1; ++i) { k = i; for(j = i + 1; j < n; ++j) if(a[k] > a[j]) k = j; if(k != i) { t = a[i]; a[i] = a[k]; a[k] = t; } } ...
元氏县19415586670: 求C++大神打个程序要求如下 急 谢谢 要能运行的!!! - ?
危羽倍洁: #include using namespace std; int main() { void fun1(); void fun2(); void fun3(); void fun4(); void fun5(); void fun6(); int c; do { puts("请输入服务选项:\n1.***\n2.***\n3.***\n4.***\n5.***\n6.***"); cin>>c; switch(c) { case 1:fun1();break; case 2:fun2();...
元氏县19415586670: 一道c++编程题 求大神解答!急! - ?
危羽倍洁: 经过上机验证没有问题哦 百度最近的格式总是会乱 格式调了半天…………好...
元氏县19415586670: 求助!!一道c++编程题 - ?
危羽倍洁: #include<iostream>#include<string.h> using namespace std; int main() {int i,j; char t,s[200]; gets(s); for(j=0;s[j];j++); if(j%2==0) j--; for(i=1;i<j;i+=2,j-=2) { t=s[i]; s[i]=s[j]; s[j]=t; } cout<<s; return 0; }
元氏县19415586670: 求大神解答一道C++题目,需要按要求编写代码,急!!!!!! - ?
危羽倍洁: 不知道你想用什么存,就用了vector,你自己改改吧 // // Created by ABacker on 6/13/2016 //#include#include using namespace std; class Employee { public: Employee(const string &name, double salary) :_name(name), _salary(salary) {} virtual ...
元氏县19415586670: 一道关于C++的难题,希望编程高手帮忙 - ?
危羽倍洁: #include <iostream> #include <string> #include <utility> #include <vector>using namespace std;bool parse(string str, vector<pair<int, int> > &vec) {bool res = true;int arr[2];int pos = 0; arr[pos] = 0;for(int i=0; i<str.length(); ++i){char c = str.at...
元氏县19415586670: C++编程,求大神帮忙 - ?
危羽倍洁: #include<iostream> #include<cmath> using namespace std; int pdxz(int, int, int); void qmj(int, int, int); int main() { int x, y, z; cin >> x >> y >> z; int m = pdxz(x, y, z); if(m) //m等于1时执行 qmj(z, y, z); cin.get(); cin.get(); return 0; } int pdxz(int x, int y, int z) ...
元氏县19415586670: 急求一道C++程序代码!谢谢!?
危羽倍洁: #include <iostream> #include <fstream> using namespace std; void main() { ifstream infile("c:\\in.txt", ios::in); ofstream outfile("c:\\out.txt", ios::out); if(!infile) { cerr<<"open error!"<<endl; exit(1); } char ch=' '; int cntAll=0, cntChar=0, cntAlb=0; ...