日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

c++一个类创建多个对象_C ++ | 创建一个类的多个对象

發布時間:2025/3/11 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c++一个类创建多个对象_C ++ | 创建一个类的多个对象 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

c++一個類創建多個對象

In the below program, we are creating a C++ program to create multiple objects of a class.

在下面的程序中,我們正在創建一個C ++程序來創建一個類的多個對象 。

/* C++ program to create multiple objects of a class */#include <iostream> #include <string> using namespace std;// class definition // "student" is a class class Student { public: // Access specifierint rollNo;string stdName;float perc; };int main() {// multiple object creationStudent std1, std2;// Accessing attributes and setting the valuesstd1.rollNo = 101;std1.stdName = "Shivang Yadav";std1.perc = 98.20f;std2.rollNo = 102;std2.stdName = "Hrithik Chandra Prasad";std2.perc = 99.99f;// Printing the valuescout << "student 1..."<< "\n";cout << "Student's Roll No.: " << std1.rollNo << "\n";cout << "Student's Name: " << std1.stdName << "\n";cout << "Student's Percentage: " << std1.perc << "\n";cout << "student 2..."<< "\n";cout << "Student's Roll No.: " << std2.rollNo << "\n";cout << "Student's Name: " << std2.stdName << "\n";cout << "Student's Percentage: " << std2.perc << "\n";return 0; }

Output

輸出量

student 1... Student's Roll No.: 101 Student's Name: Shivang Yadav Student's Percentage: 98.2 student 2... Student's Roll No.: 102 Student's Name: Hrithik Chandra Prasad Student's Percentage: 99.99

翻譯自: https://www.includehelp.com/cpp-programs/create-multiple-objects-of-a-class.aspx

c++一個類創建多個對象

總結

以上是生活随笔為你收集整理的c++一个类创建多个对象_C ++ | 创建一个类的多个对象的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。