求大神编程
#include#include bool IsHas6(int num);bool IsHas6(int num){char szBuf[11] = { 0 };sprintf_s(szBuf, sizeof(szBuf), "%d", num);for (int i = 0; i < (int)strlen(szBuf); i++){if (szBuf[i] == '6'){return true;}}return false;}int main(){int n = 0;int nCount = 0;printf("输入一个大于1的正整数n
");scanf_s("%d", &n);for (int i = 0; i <= n; i++){if (IsHas6(i)){nCount++;}}printf("%d
", nCount); return 0;}
/*如果需要测试混合运算的话可以使用Check函数中注释的代码,或者作修改;
如果使用的是vc++6.0或其他比较就的编译器,应当把
#include
using namespace std;
改为#include
并且把Check函数中得if语句删除;*/
#include
using namespace std;
class Fraction{
friend Fraction operator+(Fraction&, int);
friend Fraction operator+(int, Fraction&);
friend Fraction operator-(Fraction&, int);
friend Fraction operator-(int, Fraction&);
friend Fraction operator*(Fraction&, int);
friend Fraction operator*( int,Fraction&);
friend Fraction operator/(Fraction&, int);
friend Fraction operator/(int,Fraction&);
public:
void Print();
Fraction(int , int );
Fraction(Fraction&);
Fraction operator+(Fraction&);
Fraction operator-(Fraction&);
Fraction operator*(Fraction&);
Fraction operator/(Fraction&);
private:
void Simple();
int nume;
int deno;
};
Fraction::Fraction(int a, int b):nume(a),deno(b){
Simple();
}
Fraction::Fraction(Fraction&f){
nume = f.nume;
deno = f.deno;
}
void Fraction::Simple(){
int bo = 1;
if (nume < 0)
{
nume *= -1;
bo *= -1;
}
if (deno < 0){
deno *= -1;
bo *= -1;
}
int i = 2;
while (i <= nume){
if (nume%i == 0 && deno%i == 0){
nume /= i;
deno /= i;
i = 1;
}
i++;
}
nume *= bo;
}
void Fraction::Print(){
Simple();
if (nume == 0)
cout << 0 << endl;
else if (deno == 1)
cout << nume << endl;
else
cout << nume << "/" << deno << endl;
}
Fraction Fraction::operator+(Fraction&f){
Fraction f2(*this);
f2.deno *= f.deno;
f2.nume = f2.nume*f.deno + f.nume*deno;
return f2;
}
Fraction Fraction::operator-(Fraction&f){
Fraction f2(*this);
f2.deno *= f.deno;
f2.nume = f2.nume*f.deno - f.nume*deno;
return f2;
}
Fraction Fraction::operator*(Fraction&f){
Fraction f2(*this);
f2.deno *= f.deno;
f2.nume = nume*f.nume;
return f2;
}
Fraction Fraction::operator/(Fraction&f){
Fraction f2(*this);
f2.deno *= f.nume;
f2.nume = nume*f.deno;
return f2;
}
Fraction operator+(Fraction&f,int i){
Fraction f2(i, 1);
return f + f2;
}
Fraction operator+(int i, Fraction&f){
return operator+(f, i);
}
Fraction operator-(Fraction&f, int i){
Fraction f2(i, 1);
return f - f2;
}
Fraction operator-(int i, Fraction&f){
Fraction f2(i, 1);
return f2 - f;
}
Fraction operator*(Fraction&f,int i){
Fraction f2(i, 1);
return f*f2;
}
Fraction operator*(int i, Fraction&f){
return operator*(f, i);
}
Fraction operator/(Fraction&f, int i){
Fraction f2(i, 1);
return f / f2;
}
Fraction operator/(int i, Fraction&f){
Fraction f2(i, 1);
return f2 / f;
}
void Check(){
int nume1, deno1, nume2, deno2,i;
cout << "输入测试的数据:(注意:分母不能为0,分子、分母为正整数或负整数)
";
cout << "输入第一个测试分数的分子:
";
cin >> nume1;
cout << "输入第一个测试分数的分母:
";
cin >> deno1;
cout << "输入第二个测试分数的分子:
";
cin >> nume2;
cout << "输入第二个测试分数的分母:
";
cin >> deno2;
cout << "输入测试的整数
";
cin >> i;
if (deno1 == 0 || deno2 == 0)
throw runtime_error("分母不能为0");
Fraction f1(nume1, deno1),f2(nume2,deno2);
cout <<"("<< nume1 << "/" << deno1 <<")"<< "+" << "("<<nume2 << "/" << deno2<<")" << "= ";
(f1 + f2).Print();
cout << "(" << nume1 << "/" << deno1 << ")" << "-" << "(" << nume2 << "/" << deno2 << ")" << "= ";
(f1 -f2).Print();
cout << "(" << nume1 << "/" << deno1 << ")" << "*" << "(" << nume2 << "/" << deno2 << ")" << "= ";
(f1 *f2).Print();
cout << "(" << nume1 << "/" << deno1 << ")" << "/" << "(" << nume2 << "/" << deno2 << ")" << "= ";
(f1 / f2).Print();
cout << "(" << nume1 << "/" << deno1 << ")+(" << i << ")= ";
(f1 + i).Print();
cout << "(" << nume1 << "/" << deno1 << ")-(" << i << ")= ";
(f1 - i).Print();
cout << "(" << nume1 << "/" << deno1 << ")*(" << i << ")= ";
(f1 * i).Print();
cout << "(" << nume1 << "/" << deno1 << ")/(" << i << ")= ";
(f1 / i).Print();
cout <<"("<< i << ")+(" << nume2 << "/" << deno2 << ")" << "= ";
(i + f2).Print();
cout <<"("<< i << ")-(" << nume2 << "/" << deno2 << ")" << "= ";
(i - f2).Print();
cout <<"("<< i << ")*(" << nume2 << "/" << deno2 << ")" << "= ";
(i * f2).Print();
cout <<"("<< i << ")/(" << nume2 << "/" << deno2 << ")" << "= ";
(i / f2).Print();
/*int nume3, deno3, nume4, deno4;
cout << "输入第三个测试分数的分子:
";
cin >> nume3;
cout << "输入第三个测试分数的分母:
";
cin >> deno3;
cout << "输入第四个测试分数的分子:
";
cin >> nume4;
cout << "输入第四个测试分数的分母:
";
cin >> deno4;
Fraction f3(nume3, deno3), f4(nume4, deno4);
cout << "((" << nume1 << "/" << deno1 << ")+(" << nume2 << "/" << deno2 << ")-(" << i << "))*(";
cout << nume3 << "/" << deno3 << ")/(" << nume4 << "/" << deno4 << ")= ";
((f1 + f2 - i)*f3 / f4).Print();*/
}
int main(){
Check();
return 0;
}
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语言编程,输入2个整数 x和n,输出 x 的n次方
include<stdio.h>int main(void){ int i, x, n, iResult = 1.0; printf("%s\\n", "请输入底数 x:"); scanf("%d", &x); printf("%s\\n", "请输入指数 n:"); scanf("%d", &n); for(i=0; i<n; i++) iResult *= x; printf("%d 的 %d...
c++编程,求大神帮忙解答
C++代码如下:include <bits\/stdc++.h> \/\/ C++万能头文件 using namespace std;int dx[4] = {-1, 1, 0, 0};int dy[4] = {0, 0, -1, 1};int n, m;char mat[3000][3000]; \/\/ 字符矩阵 int dp[3000][3000][6]; \/\/ 记忆化搜索 string s = "IAKCSP";int dfs(int x,...
求大神!用C语言编程!做一个m行n列的矩阵
参考代码如下:include<stdio.h> define M 10 define N 10 void main(){ int a[M][N],i,j,sum;printf("input 2D array values:");for(i=0;i<M;i++){ for(j=0;j<N;j++){ scanf("%d",&a[i][j])} } \/\/ output 2D array for(i=0;i<M;i++){ for(j=0;j<N;j++...
求助大神,编程实现输入一个人的年龄,计算并输出其出生年份
include <stdio.h>#include int main( ){ int year,x; time_t nowtime; struct tm *timeinfo; time( &nowtime ); timeinfo = localtime( &nowtime ); year = timeinfo->tm_year + 1900; while (1) { printf("请输入你的年龄:");scanf("%d",&x); if (x>0&&x<=100) { ...
Java编程,大神求帮忙,马上交作业了,现场等
代码如下,关键地方的注释我都有加,有问题可以继续追问 import java.io.UnsupportedEncodingException;import java.util.Scanner;import java.util.regex.Matcher;import java.util.regex.Pattern;public class Demo { public static void main(String[] args){ Scanner scanner = new Scanner(System.in);...
来个大神帮忙加工中心编程,谢谢!
如采用G90方式编程, 跟现在的位置A点没关系,与移动后的位置B点有关。B的坐标值为(X80,Y80)即:G90 X80. Y80.如采用G91方式编程,根据概念: 与移动方向和移动量有关 如下图:刀具现在位置往X正方向移动 X+ 刀具现在位置往X负方向移动 X- 刀具现在位置往Y正方向移动 Y+ 刀具现在位置往...
请C语言大神编程!
这个行不?这个只有新增功能,要编辑和删除的话,用结构体链表更容易点。加点说明,你看着自己去改吧。include "stdio.h"include "stdlib.h"typedef struct {int num; \/*学号*\/ char name[50]; \/*姓名*\/ int score[4];} msg; \/*三科成绩及平均分放在数组score里*\/ int input(msg ...
...16+...的前n项之和,n由用户从键盘输入,求大神用c++编程
\/\/首先是分析规律 1可以看作是 1\/1 1\/4 分母是等差数列是 1 4 7 10 13相差为3 \/\/另外符号是 正 负 正 负这样 include <iostream> using namespace std;int main(){ int n;cin>>n; \/\/输入N的值 if(n<=0) \/\/如果输入的是0或者负数 cout<<"input error!";int i=1;int ...
c++编程题,求大神解答。
基本思想是计算相邻的机器人每轮发生碰撞的时间,从小到大排列后依次发生碰撞 剩下的机器人相邻关系会改变,重新计算碰撞时间,重复上述步骤,直到没有碰撞发生 C++代码如下:include <bits\/stdc++.h> \/\/ C++万能头文件 using namespace std;using tri = tuple<double, int, int>; \/\/ 发生碰撞的...
一道c++编程问题,求大神打出代码,悬赏全给你
写了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...
夫注泰宾: . 1 私人小Form_Click()量表(-300,200) - (300,-200)线(0,200) - (0,-200)线(-300,0) - (300,0) R1 = 150 R2 = 190 对于i = 0到360步0.01 一= I * 3.14 / 180...
大名县18497552926: 跪求C++大神帮忙编个程序!急需!!!感激不尽!!! - ?
夫注泰宾: 说实话,比较简单. 我这会想休息一下,就简单给你写个框子吧. typedef double (*Func) (double x); //定义一个函数指针,注意我只简单写一个参数的函数指针.double e_pow_x(double x) //e^x {return ......;// 自己找数学库中的函数 }double ...
大名县18497552926: 求大神,帮忙编一个程序 - ?
夫注泰宾: 我觉得可以反推,优先除以1.2以更快地到达10,但这样会不会导致无解也是个问题,你可以在csdn上问一问看有没有牛人可以比较全面地分析一下.#include <stdio.h> #include <math.h> int round(double x) {return (int)(x+0.5); } int main() {int ...
大名县18497552926: 求大神用C语言编程 - ?
夫注泰宾: int Str_length(char *st){ int i=0; while(st[i]!='\0') i++; return i; }
大名县18497552926: 求大神编个程序: - ?
夫注泰宾: 12345678910111213141516171819202122232425 publicclasstest {publicstaticvoidmain(String[] args) throwsException { String wordStr = "qwe wesa qwesda qweqqe qweqweaqwrwerw qa qweqaaa"; getWord(wordStr); }...
大名县18497552926: 求大神帮忙做一道C语言简单编程,要求如下 - ?
夫注泰宾: #include int main() { char c = 'Y'; float x,y,z; char operate; while(c=='Y' || c=='y') { printf("please enter number1:"); scanf("%f",&x); printf("please enter operate:"); getchar(); scanf("%c",&operate); printf("please enter number2:"); scanf("%f...
大名县18497552926: 求C++编程大神从键盘输入两个两位数a、b,将其组合成一个四位数输出(千位是a的个位,百位是b的十位,十位是b的个位,个位是a的十位) - ?
夫注泰宾:[答案] 不想敲代码了,主要的给你说一下. a的个位是 a % 10 a的十位是 a / 10 因为b的十位占用了输出的数的百位,个位占用了输出的数的十位,所以b * 10就可以满足要求了. 所以最后输出的数 Ans = a % 10 * 1000 + b * 10 + a / 10;代码里核心就是这一句...
大名县18497552926: 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) ...
大名县18497552926: 求大神写一下c++程序.. - ?
夫注泰宾: #include using namespace std;class Dot {public: double x, y; Dot() {} Dot(double x, double y) { this->x = x; this->y = y; } void print() const { cout...
大名县18497552926: 求大神编JAVA程序 - ?
夫注泰宾: 模拟猜大小的简单Java游戏程序如下:import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Random; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing....