C++primer plus 第三 四章的习题(自己写的)

第一次写自己的东西,希望有人认可吧!!
#include<iostream>
#include<stdlib.h>
//第三章习题
int main()
{
using namespace std;
const int i = 10;
int j;
cout << "Enter your tall______\b\b\b\b";
cin >> j;
int s = j / 10;
int d = j % 10;
cout << "你的身高" << s << "英尺" << d << "英寸" << endl;
system("pause");
return 0;
}


#include<iostream>
#include<stdlib.h>
//第三章习题
int main()
{
using namespace std;
const int i = 12;
const float j = 0.0254f;
const float k = 2.2f;//这就不会被截断了


int foot, inch;
cout << "Enter your height(including foot and inch)";
cin >>foot>>inch ;
float height = (i * foot + inch)*j;
cout << "Enter your pound";
int pound;
cin >> pound;
float weight = pound*k;
cout << "你的身高" << height << "米" << "你的体重" <<weight<< "千克" << endl;
cout << "你的BMI指数为" << weight / (height*height);
system("pause");
return 0;
}


#include<iostream>
#include<stdlib.h>
//第三章习题
int main()
{
using namespace std;

cout << "Enter your latitude in degress ,minutes,and seconds" << endl;
int degress, minutes, seconds;
cout << "Enter your degress:";
cin >> degress;
cout << "Enter your minutes:";
cin >> minutes;
cout << "Enter your seconds:";
cin >> seconds;
cout << degress << "degress " << minutes << "minutes " << seconds << "seconds = "
<< degress + (minutes * 60 + seconds) / 3600.0<<"degress";
system("pause");
return 0;
}




#include<iostream>
#include<stdlib.h>
//第三章习题
int main()
{
using namespace std;


cout << "Enter your number of seconds" << endl;
long seconds; 
cin >> seconds;
cout << seconds << " seconds= " << seconds / 24 / 60 / 60 << " days"
<< seconds / 60 / 60 % 24 << "hours " << seconds / 60 % 60 << "minutes "
<< seconds % 60 << "seconds" << endl;
system("pause");
return 0;
}




#include<iostream>
#include<stdlib.h>
//第三章习题
int main()
{
using namespace std;


    cout << "Enter the world's population";
long long world;
cin >> world;
cout << "Enter the us population";
long long us;
cin >> us;
cout << "the proportion is"<<(float)us/world*100<<"%" << endl;


system("pause");
return 0;
}




#include<iostream>
#include<stdlib.h>
//第三章习题
int main()
{ 
using namespace std;


cout << "Enter the distance";
double distance;
cin >> distance;
cout << "Enter the us gas";
double gas;
cin >> gas;
cout << "Europe:";
cout << gas / (distance / 100) << endl;




cout << "Enter europe";
double dg,pet,dis;
cin >> dg;
pet = dg * 100/3.875;
dis = 62.14;
cout << "American" << dis /pet*100 << endl;
system("pause");
return 0;
}


#include<iostream>
#include<stdlib.h>
int main()
{
using namespace std;
const int lenth = 20;
struct stu
{
char f_name[lenth];
char l_name[lenth];
char grade;
int age;
}stu1;
cout << "what's your first name?";
cin.getline(stu1.f_name, lenth);
cout << "what's your last name?";
cin.getline(stu1.l_name, lenth);
cout << "what degree do you deserve?";
cin >> stu1.grade;
cout << "what's your age?";
cin >> stu1.age;


cout << "Name:" << stu1.l_name << "," << stu1.f_name << endl;
cout << "Grade:" << (char)(stu1.grade + 1) << endl;
cout << "Age:" << stu1.age << endl;
system("pause");
return 0;
}




#include<iostream>
#include<stdlib.h>
#include<string>


int main()
{
using namespace std;
string name;
string dessert;


cout << "Enter your name:\n";
getline(cin, name);


cout << "Enter your favorate dessert\n";
getline(cin, dessert);


cout << "I have some delicious " << dessert ;
cout << " for you, " << name << endl;




system("pause");
return 0;
}




#include<iostream>
#include<stdlib.h>
#include<string>


int main()
{
using namespace std;
const int lenth = 10;
char f_name[lenth];
char l_name[lenth];



cout << "Enter your first name:";
cin.getline(f_name, 10);


cout << "Enter your last name:";
cin.getline(l_name, 10);


cout << "your full name is " << f_name<<" "<<l_name<<endl;


system("pause");
return 0;
}




#include<iostream>
#include<stdlib.h>
#include<string>


using namespace std;
int main()
{


struct CandyBar
{
string  brand;
float weight;
int    calory;
}snack{"Mocha Munch",2.3f,350};


cout << snack.brand << endl;
cout << snack.calory << endl;
cout << snack.weight << endl;


system("pause");
return 0;
}




#include<iostream>
#include<stdlib.h>
#include<string>


using namespace std;
int main()
{


struct CandyBar
{
string  brand;
float weight;
int    calory;
};
CandyBar snack1{ "Mocha Munch", 2.3f, 350 };
CandyBar snack2{ "Mocha Munch", 2.3f, 350 };
CandyBar snack3{ "Mocha Munch", 2.3f, 350 };


cout << snack1.brand << endl;
cout << snack1.calory << endl;
cout << snack1.weight << endl;


cout << snack2.brand << endl;
cout << snack2.calory << endl;
cout << snack2.weight << endl;


cout << snack3.brand << endl;
cout << snack3.calory << endl;
cout << snack3.weight << endl;


system("pause");
return 0;
}


#include<iostream>
#include<stdlib.h>
#include<string>


using namespace std;
int main()
{


struct CandyBar
{
string  company;
float R;
int    weight;
};
CandyBar snack1;
cout << "please enter your company:";
getline(cin, snack1.company);
cout << "please enter your R:";
cin >> snack1.R;
cout << "please enter your weight:";
cin >> snack1.weight;
cout << "Company: " << snack1.company << " R: "
<< snack1.R << " Weight: " << snack1.weight << endl;
system("pause");
return 0;
}


#include<iostream>
#include<stdlib.h>
#include<string>


using namespace std;
int main()
{


struct CandyBar
{
string  company;
float R;
int    weight;
};
CandyBar *snack1=new CandyBar;
cout << "please enter your company:";
getline(cin, snack1->company);
cout << "please enter your R:";
cin >> snack1->R;
cout << "please enter your weight:";
cin >> snack1->weight;
cout << "Company: " << snack1->company << " R: "
<< snack1->R << " Weight: " << snack1->weight << endl;
  delete snack1;
system("pause");
return 0;
}




#include<iostream>
#include<stdlib.h>
#include<string>


using namespace std;
int main()
{


struct CandyBar
{
string  company;
float R;
int    weight;
};
int size;
cout << "Enter your size:";
cin >> size;


CandyBar *snack1 = new CandyBar[size];
for (int i = 0; i < size; i++)
{
cin.get();
cout << "please enter your company:";
getline(cin, snack1->company);
cout << "please enter your R:";
cin >> snack1->R;
cout << "please enter your weight:";
cin >> snack1->weight;
cout << "Company: " << snack1->company << " R: "
<< snack1->R << " Weight: " << snack1->weight << endl;
snack1++;
}
snack1 -= size;
delete [] snack1;
system("pause");
return 0;
}



#include<iostream>
#include<stdlib.h>
#include<string>


using namespace std;
int main()
{


struct CandyBar
{
string  company;
float R;
int    weight;
};
int size;
cout << "Enter your size:";
cin >> size;


CandyBar *snack1 = new CandyBar[size];
for (int i = 0; i < size; i++)
{
cin.get();
cout << "please enter your company:";
getline(cin, snack1->company);
cout << "please enter your R:";
cin >> snack1->R;
cout << "please enter your weight:";
cin >> snack1->weight;
cout << "Company: " << snack1->company << " R: "
<< snack1->R << " Weight: " << snack1->weight << endl;
snack1++;
}
snack1 -= size;
delete[] snack1;
system("pause");
return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值