Search
 
SCRIPT & CODE EXAMPLE
 

CPP

structure and function c++

#include <iostream>

using namespace std;

struct smartphone{
    string name;
    int storageSpace;
    string color;
    float price;
};

struct singer{
    string name;
    string band;
    int age;
    smartphone mySmartPhone;
};

void smartPhoneInfo(smartphone smartphone){
    cout << "smartphone name: " << smartphone.name << endl;
    cout << "smartphone storage space: " << smartphone.storageSpace << endl;
    cout << "smartphone color: " << smartphone.color << endl;
    cout << "smartphone price: " << smartphone.price << endl;
}

void singerInfo(singer a){
   cout <<"Name: " << a.name << endl;   
   cout <<"Band: " << a.band << endl;
   cout <<"Age: " << a.age << endl;
   smartPhoneInfo(a.mySmartPhone);
}

int main(){
    smartphone smartphone1;
    smartphone1.name = "Oppo";
    smartphone1.storageSpace = 128;
    smartphone1.color = "Gold";
    smartphone1.price = 5500;
    
    smartphone smartphone2;
    smartphone2.name = "Iphone 12";
    smartphone2.storageSpace = 64;
    smartphone2.color = "Black";
    smartphone2.price = 19000;                                                                
    
    singer a;
    a.name = "Jennie";
    a.age = 20;
    a.band = "Black Pink";
    a.mySmartPhone = smartphone2;
    singerInfo(a);
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: format string cpp 
Cpp :: c++ char array to int 
Cpp :: how to declare 1-D array in C/C++ 
Cpp :: dynamically generating 2d array in cpp 
Cpp :: c++ map iterator 
Cpp :: cpp mst 
Cpp :: opencv c++ hello world 
Cpp :: combination code c++ 
Cpp :: min vector c++ 
Cpp :: how to convert int to string c++ 
Cpp :: copy 2 dimensional array c++ 
Cpp :: how to copy one vector to another 
Cpp :: syntax c++ 
Cpp :: c++ switch case break 
Cpp :: how to convert int to std::string 
Cpp :: c++ printf char as hex 
Cpp :: c++ nested switch statements 
Cpp :: c++ string contains 
Cpp :: how to make copy constructor in c++ 
Cpp :: C++ string initialization 
Cpp :: c++ get type name 
Cpp :: ray sphere intersection equation 
Cpp :: count bits c++ 
Cpp :: c++ default parameters 
Cpp :: C++ String Copy Example 
Cpp :: c++ string element access 
Cpp :: powershell get uptime remote computer 
Cpp :: palindrome checker in c++ 
Cpp :: vector find 
Cpp :: how to get the time in c++ as string 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =