In this video we will discuss about Array, IF-ELSE IF - ELSE & Create a Phone-store program. We can start from array. Array is a structured data type that is using for stores a number of data from the same type. Array has characteristics such as data types that can be hold more than one data, access time equals for every element, accessible at random and also the most convenient data storage structure. Then, we learn about IF_ELSE IF_ELSE conditions. First, we will explain about IF. It's a condition where the content inside is correct or that condition is true then it will be executed. Second, we have additional condition is ELSE IF that will be executed if the condition of IF is false or the value is not appropriate. And last, we have last optional that is ELSE. It will be used if the contents from IF not correct or the value is false. Now, we will to create the program about create a simple program for Phone-Store in C++ programming language using CodeLite.
This video explained in English - HD 720p
#include
#include
#include
using namespace std;
int main()
{
string code, fname, lname, address, anw;
string a[1] = {"DPhone"};
string b[3] = {"Gray","Silver", "Gold"};
int price[3] = {4000000, 4500000, 5000000};
cout<<"-------------WELCOME TO DR-STORE-------------"<<endl;
cout<<endl;
cout<<"Please entry in below"<<endl;
cout<<endl;
cout<<"Enter first name: "; cin>>fname;
cout<<"Enter last name: "; cin>>lname;
cout<<"Enter Address: "; cin>>address;
cout<<endl;
cout<<"------------DPhone Collection-------------"<<endl<<endl;
cout<<"Hallo "<<fname<<" "<<lname<<" !,Please check our product in below:"<<endl;
cout<<"--------------------------------------------"<<endl;
cout<<"Code : DGRAY => "<<a[0]<<"-"<<b[0]<<" \t IDR."<<price[0]<<endl;
cout<<"Code : DSLVR => "<<a[0]<<"-"<<b[1]<<"\t IDR."<<price[1]<<endl;
cout<<"Code : DGOLD => "<<a[0]<<"-"<<b[2]<<" \t IDR."<<price[2]<<endl;
cout<<"------------------------------------------"<<endl;
cout<<"Enter the code for phone you want to purchase: "; cin>>code;
if (code == "DGRAY")
{
cout<<"Phone : "<<a[0]<<endl;
cout<<"Color : "<<b[0]<<endl;
cout<<"Price : "<<"IDR."<<price[0]<<endl;
cout<<"Are you sure to buy this DPHONE ?";
cin>>anw;
cout<<endl;
if (anw=="y"){
cout<<"---------THANKS FOR PURCHASE-----------"<<endl<<endl;
cout<<"Name : "<<fname<<" "<<lname<<endl;
cout<<"Address : "<<address<<endl;
cout<<"Purchase success !"<<endl;
cout<<endl;
}
else if (anw=="n")
cout<<"----------THANK YOU FOR VISITING------- \n ---------PLEASE COME AGAIN !------"<<endl<<endl;
}
else if (code == "DSLVR")
{
cout<<"Phone : "<<a[0]<<endl;
cout<<"Color : "<<b[1]<<endl;
cout<<"Price : "<<"IDR."<<price[1]<<endl;
cout<<"Are you sure to buy this DPHONE ?";
cin>>anw;
cout<<endl;
if (anw=="y"){
cout<<"---------THANKS FOR PURCHASE-----------"<<endl<<endl;
cout<<"Name : "<<fname<<" "<<lname<<endl;
cout<<"Address : "<<address<<endl;
cout<<"Purchase success !"<<endl;
cout<<endl;
}
else if (anw=="n")
cout<<"----------THANK YOU FOR VISITING------- \n ---------PLEASE COME AGAIN !------"<<endl<<endl;
}
else if (code == "DGOLD")
{
cout<<"Phone : "<<a[0]<<endl;
cout<<"Color : "<<b[2]<<endl;
cout<<"Price : "<<"IDR."<<price[2]<<endl;
cout<<"Are you sure to buy this DPHONE ?";
cin>>anw;
cout<<endl;
if (anw=="y"){
cout<<"---------THANKS FOR PURCHASE-----------"<<endl<<endl;
cout<<"Name : "<<fname<<" "<<lname<<endl;
cout<<"Address : "<<address<<endl;
cout<<"Purchase success !"<<endl;
cout<<endl;
}
else if (anw=="n")
cout<<"----------THANK YOU FOR VISITING------- \n ---------PLEASE COME AGAIN !------"<<endl<<endl;
}
else
cout<<"Invalid code !"<<endl<<endl;
return 0;
}
You can learn about video tutorial of c++ in below :