اذهب إلى المحتوى
  • 0

واجب في structure ++c احتاج جوابة قبل يوم الثلوث >_<

Alone Moon

السؤال

1.      A phone number, such as (966) 767-8900, has three parts: the area code (966), the exchange (767), and the number (8900). Write a program that uses a structure to store these three parts of a phone number separately. Call the structure phone.

2.      Create two structure variables of type phone. Initialize one, and have the user input a number for the other one. Then display both numbers.

Modify the program so that the program asks names of 10 persons and phone numbers. Use the phone structure in the previous exercise and create another structure that includes names of persons and phone structure

رابط هذا التعليق
شارك على الشبكات الإجتماعية

Recommended Posts

  • 0

هكذا يحل الفرع الأول والثاني.. يبقى عليك تفهم الفكرة وتحل الفرع الثالث

#include <iostream>
#include <string>
#include <regex>
using namespace std;

struct Phone {
string AreaCode;
string Exchange;
string Number;
};

int main() {
struct Phone origin = {"212", "767", "8900"};
struct Phone userInput;
string userPhone;

cout << "\nPlease enter phone number in format: (xxx) xxx-xxxx\n";
getline(cin, userPhone);

regex reg("[\\s()-]+");
userPhone = regex_replace(userPhone, reg, "");

userInput.AreaCode = userPhone.substr(0,3);
userInput.Exchange = userPhone.substr(3,3);
userInput.Number = userPhone.substr(6,4);

cout << "\nOrigin structure" << endl
<< "AreaCode: " << origin.AreaCode << endl
<< "Exchange: " << origin.Exchange << endl
<< "Number: " << origin.Number << endl;

cout << "\nUser Input structure" << endl
<< "AreaCode: " << userInput.AreaCode << endl
<< "Exchange: " << userInput.Exchange << endl
<< "Number: " << userInput.Number << endl;

return 0;
}

 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...