1. 程式人生 > 其它 >東北大學秦皇島分校通訊工程中外合作2020級C/CPP語言實驗7

東北大學秦皇島分校通訊工程中外合作2020級C/CPP語言實驗7

技術標籤:東北大學秦皇島分校通訊工程中外合作2020級C語言實驗課

1.閱讀下面的程式,在電腦中錄入、執行,說明程式的功能(要有執行截圖)
1.Read the following program, input it into computer, run it and interpret its functions
在這裡插入圖片描述

#include<iostream>
using namespace std;
int main()
{
	cout<<"Enter a degree in Celsius: ";
	double celsius;
	cin>>
celsius; double fahrenheit=(9.0/5)*celsius+32; cout<<"Fahrenheit degree is "<<fahrenheit; return 0; }

2.閱讀下面的程式,在電腦中錄入,說明程式的功能(要有執行截圖)
2.Read the following program, input it into computer, run it and interpret its functions
在這裡插入圖片描述

#include<iostream>
using namespace std;

int main
() { cout<<"Enter the radius and length of a cylinder: "; double radius,length; cin>>radius>>length; double area=radius*radius*3.14159; double volume=area*length; cout<<"The area is "<<area<<endl; cout<<"The volume is "
<<volume<<endl; return 0; }

3.將下面的演算法翻譯成C++程式碼:
3.Translate the following algorithm into C++ code:
步驟1:宣告double型變數miles,初值為100
Step 1: Declare a double variable named miles with initial value 100
步驟2:宣告double型常量KILOMETERS_PER_MILE,初值為1.609
Step 2: Declare a double constant name KILOMETERS_PER_MILE with value 1.609
步驟3:宣告double型變數kilometers,將miles和KILOMETERS_PER_MILE相乘,並將結果賦給kilometers
Step 3: Declare a double variable named kilometers, multiply miles and KINOMETERS_PER_MILE, and assign the result to kilometers.
步驟4:在console介面顯示kilometers的值
Step 4: Display kilometers to the console.
問題:第4步後,顯示的kilometers的值是多少?
What is kilometers after Step 4?

#include<iostream>
using namespace std;
int main()
{
	double miles=100;
	const double KILOMETERS_PER_MILE=1.609;
	double kilometers=KILOMETERS_PER_MILE*miles;
	cout<<kilometers;
	return 0;
}

4.寫一個函式(名稱為MinMax),該函式能用引用返回兩個引數a和b的最大值和最小值。在main函式裡對該函式進行測試:
4.Write a function named MinMax that returns the minimum and maximum number of two variables a and b with double type by reference argument, and then write main function to test MinMax as follows:
[1] 定義兩個變數x和y
[1]defines two variables named x and y
[2] 從鍵盤輸入兩個數,並賦給x和y
[2]inputs values to them from keyboard
[3] 呼叫MinMax函式,並返回x和y的最小值和最大值
[3]calls MinMax to compute their minimum and maximum
[4] 輸出最小值和最大值
[4]outputs the minimum and maximum.

5.編寫兩個過載函式(名稱為valabs),它們分別能返回int型資料和double型資料的絕對值。編寫main函式對它們進行測試。
5.Write two overload functions named valabs that return the absolution of value with int type, double type respectively, then write main function to test valabs.

6.編寫函式,名稱為wadd,它能返回w * a + (1 – w) * b的結果,其中a、b和w都是double型引數,且w的預設值為0.5。編寫main函式對該函式進行測試。
6.Write a function named wadd that returns the result of w * a + (1 – w) * b, and a, b and w are double type, w is with default value 0.5, then write main function to test wadd.