我尝试从输入中找到最大(最高)值,但该值转换为其他值。例如,当我为Mahasiswa.ipk放3时,它转换为0,并且Mahasiswa.nim转换为6946913.如何才能在输出中显示实际值?
using namespace std;
struct Mhs
{
char nama[30];
int nim[20];
float ipk[2];
};
int BacaDataMhs(int N);
int TampilIpkMaxMin(int N);
int TampilIpkDua(int N); /// edited : I can use this function
int main(int argc, char ** argv)
{
int N;
cout << "Input Value : "; cin >> N;
TampilIpkMaxMin(N);
int BacaDataMhs(int N);
}
int BacaDataMhs(int N)
{
struct Mhs Mahasiswa[N];
int i;
for(i=0; i<N; i++)
{
cout << "NAMA : "; cin >> Mahasiswa[i].nama;
cout << "NIM : "; cin >> Mahasiswa[i].nim[i];
cout << "IPK : "; cin >> Mahasiswa[i].ipk[i];
cout << endl;
}
}
int TampilIpkMaxMin(int N)
{
struct Mhs Mahasiswa[N];
int i;
int max=Mahasiswa[0].ipk[0];
int min=Mahasiswa[0].ipk[0];
int index_max=0;
int index_min=0;
for(i=0; i<N; i++)
{
if (max<Mahasiswa[i].ipk[i]) //calculate the higgest value
{
max=Mahasiswa[i].ipk[i];
index_max=i;
}
if (min>Mahasiswa[i].ipk[i])
{
min=Mahasiswa[i].ipk[i];
index_min=i;
}
}
cout << "Nilai Tertinggi :" <<endl; //show the higgest value
cout << "nama "<< Mahasiswa[index_max].nama << endl;
cout << "nim "<< Mahasiswa[index_max].nim [index_max] << endl;
cout << "ipk "<< Mahasiswa[index_max].ipk [index_max] << endl;
}
int TampilIpkDua(int N) // i can use this function but not with int TampilMhsMaxMin (int N )
{
struct Mhs Mahasiswa[N];
int i;
for(i=0; i<N; i++)
{
if (Mahasiswa[i].ipk[i]>2)
{
cout << "nama "<< Mahasiswa[i].nama << endl;
cout << "nim "<< Mahasiswa[i].nim[i] << endl;
cout << "ipk "<< Mahasiswa[i].ipk[i] << endl;
}
}
}
//编辑
答案 0 :(得分:0)
我仍然无法弄清楚本练习的目的,但您似乎并不了解范围或参数的工作原理。
(我想)你想要一个Mhs的集合,可以在你的函数中进行修改和读取。定义它们的最简单的地方是main,它是调用图中的共同祖先。
具有运行时边界的数组不是C ++,尽管有些编译器会接受它们。 std :: vector是一个比通用数组更好的容器。
不要将using namespace std放在全局范围内,它会带来太多的名字。
import tensorflow as tf
import numpy as np
a = np.array([1, 2, 3, 4, 5])
fn = lambda x: x**2
squares = tf.map_fn(fn=fn, elems=a)