Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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);
}
 
PREVIOUS NEXT
Tagged: #structure #function
ADD COMMENT
Topic
Name
9+2 =