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 :: hashmap c++ 
Cpp :: c++ set swap 
Cpp :: map count function c++ 
Cpp :: long pi in c++ 
Cpp :: initialize a vector to 0 
Cpp :: how to add space in c++ 
Cpp :: search by value in map in stl/cpp 
Cpp :: tuple vector c++ 
Cpp :: c++ recursion 
Cpp :: c++ insert variable into string 
Cpp :: Fisher–Yates shuffle Algorithm c++ 
Cpp :: int max in c++ 
Cpp :: convert wchar_t to to multibyte 
Cpp :: prevent copy c++ 
Cpp :: adddynamic ue4 c++ 
Cpp :: c++ delay 
Cpp :: Initialize Vector Iterator Through Vector Using Iterators 
Cpp :: square gcode 
Cpp :: c++ cin 
Cpp :: declare a tab c++ 
Cpp :: Program to print full pyramid using 
Cpp :: unordered_map c++ 
Cpp :: c++ preprocessor commands 
Cpp :: c++ string concatenation 
Cpp :: how to rotate a matrix 90 degrees clockwise 
Cpp :: flutter text direction auto 
Cpp :: calling by reference c++ 
Cpp :: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/ 
Cpp :: read a file line by line c++ struct site:stackoverflow.com 
Cpp :: unambiguous 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =