بوابة الثانوية العامة المصرية

بوابة الثانوية العامة المصرية (https://www.thanwya.com/vb/index.php)
-   كليات المجموعة الرياضية (https://www.thanwya.com/vb/forumdisplay.php?f=1688)
-   -   OOP / C++/C / JAVA Let's Program (https://www.thanwya.com/vb/showthread.php?t=237398)

ahmed abobakr 09-08-2010 02:13 AM

OOP / C++/C / JAVA Let's Program
 
السلام عليكم ورحمة الله وبركاته

انا لقيت ان المنتدى انشغل بأسئلة خاصة بالتنسيق والاختيار وحاجات زى كدا بنرحب بها طبعا ولكنها اثرت على مستوى المنتدى بالسلب

لهذا قررت اعمل الموضوع دا واتمنى ان يكون فى مشاركة وخاصة انه عملى جدا

وهو عن البرمجة

اى حد عنده مسأله برمجة بلغات oop / c++/c / java وانا اخترت ال 4 لغات دول لانهم المشتركين فى غالبية الكليات

يكتبها ونشترك كلنا فى حلها ونناقش الحلول وبكده هننشط المنتدى مرة اخرى

مش شرط انك تكون مش عارف المسألة عشان تكتبها ممكن يكون غيرك مش عارفها
واعتقد بكدا هنقدر ننمى مهاراتنا ونستفيد من المنتدى احسن من كدا


انا هبدأ بمسألة كنت اخدها فى الكلية السنة اللى فاتت كانت ضمن مجموعة مسائل فى مشروع للمادة .

--------------------------------------------------------------------------
oop problem #1

Create a SavingsAccount class. Use a static data member annual InterestRate to store the annual interest rate for each of the savers.

Each member of the class contains a private data member savingsBalance indicating the amount the saver currently has on deposit.

Provide member function calculateMonthl yInterest that calculates the monthly interest by multiplying the balance by annual InterestRate divided by 12; this interest should be added to savingsBalance.

Provide a static member function modifyInterestRate that sets the static annualInterestRate to a new value.


Write a driver program to test class SavingsAccount. Instantiate two different
objects of class SavingsAccount, saver1 and saver2, with balances of$2000.00 and $3000.00,respectively.

Set the annual InterestRate to 3 percent. Then calculate the monthly interest and
print the new balances for each of the savers.

Then set the annualInterestRate to 4 percent and calculate the next month’s interest and print the new balances for each of the savers

معكم المسألة نفكر فيها وبعد فترة من المناقشة والتفكير هنزل حلها

ahmed abobakr 11-08-2010 11:43 PM

السلام عليكم

للاسف الموضوع ملقاش اى اهتمام من الاعضاء على عكس ما كنت متوقع

وده حل المسألة


كود:

#include<iostream>
using namespace std;
class SavingAccount
{
      private:
              static float annualinterestrate;
              double savingsBalance;
      public:
            SavingAccount():savingsBalance(0){}         
            SavingAccount(double d){savingsBalance=d;}
            void calculateMonthlyInterest();
            static void modifyInterestRate(float );
            double getBalance();
};
/******************************************************************************/
double SavingAccount::getBalance()
{
      return savingsBalance;
}
/******************************************************************************/
float SavingAccount::annualinterestrate=0;
/******************************************************************************/
void SavingAccount::calculateMonthlyInterest()
{
      double x;
      x=savingsBalance*annualinterestrate/12;
      cout<<"\n The Monthly Interest is : "<<x<<endl<<endl;
      savingsBalance+=(savingsBalance*annualinterestrate)/12;
      cout<<" The Final Balance  For Saver 1 Is : "<< savingsBalance<<endl<<endl;     
}
/******************************************************************************/
void SavingAccount:: modifyInterestRate(float r)
{
      annualinterestrate=r;
}
/******************************************************************************/
int main()
{
    SavingAccount s;
    SavingAccount saver1(2000);
    SavingAccount saver2(3000);
    s.modifyInterestRate(.03);
    cout<<" \n\n FOR SAVER 1 WITH BALANCE = 2000.00 $ \n";
    cout<<"====================================================================\n\n";
    saver1.calculateMonthlyInterest();
    cout<<" \n\n FOR SAVER 2 WITH BALANCE = 3000.00 $ \n";
    cout<<"====================================================================\n\n";
    saver2.calculateMonthlyInterest();
    s.modifyInterestRate(0.04);
    cout<<" \n AFTER CHANGING THE ANNUAL INTEREST RATE TO .04 ";
    cout<<"\n\n ===============================================================\n";
    saver1.calculateMonthlyInterest();
    cout<<"====================================================================\n\n";
    saver2.calculateMonthlyInterest();
    system("pause");
    return 0;
}


badnamef4 01-09-2010 03:13 AM

بسم الله الرحمن الرحيم
السلام عليكم و رحمة الله و بركاته
أنا عندي سؤال احتمال كبير يبقى أهبل
ليه بنكتب using namespace std; مش using std; زي في أي namespace عادية
السلام عليكم و رحمة الله و بركاته

عبدو 8 12-09-2010 02:50 AM

اقتباس:

المشاركة الأصلية كتبت بواسطة badnamef4 (المشاركة 2606883)
بسم الله الرحمن الرحيم
السلام عليكم و رحمة الله و بركاته
أنا عندي سؤال احتمال كبير يبقى أهبل
ليه بنكتب using namespace std; مش using std; زي في أي namespace عادية
السلام عليكم و رحمة الله و بركاته

ههههه

يمكن عشان كدا شكلها احلى

سووري ,, بس انا والله بموت في البرمجة بس مش فاهم اي حاجه ,, لسه مبتدئ يعني :049gc0:

tito man 1 04-10-2010 08:01 PM

شكرا ليك يا باشمهندس احمد بس عاوزين مسائل على ال سى ++ الله يكرمك

ahmed abobakr 13-11-2010 02:04 PM

اقتباس:

المشاركة الأصلية كتبت بواسطة badnamef4 (المشاركة 2606883)
بسم الله الرحمن الرحيم
السلام عليكم و رحمة الله و بركاته
أنا عندي سؤال احتمال كبير يبقى أهبل
ليه بنكتب using namespace std; مش using std; زي في أي namespace عادية
السلام عليكم و رحمة الله و بركاته

السلام عليكم
كل عام وانتم بخير
اسف للغياب الطويل لظروف الدراسة
بالنسبة لسؤالك يابشمهندس هوا مش سؤال اهبل ولا حاجة

ودا الرد على سؤالك

using namespace std
library in c and c++ that contains set of classes , objects and functions
the commonly used functions from this library is cout , cin , endl
if you write ur program without using namespace std the compiler will give u error function(cout,cin,endl.....) undeclared

to declare this functions without writing using namespace std
use this syntax
std::cout
std::cin
std::endl

see examples

1- with using namespace std

كود:

#include<iostream>
using  namespace std;
int main()
{
    cout<<"hello world"<<endl; 
    system("pause");
    return 0;
}

2 - without using namespace std

كود:

#include<iostream>
int main()
{
    std::cout<<"hello world"<<std::endl;
    system("pause");
    return 0;
}






اتمنى انى اكون وفقت فى توصيل المعلومة ولى فى اى استفسار انا موجود


















جميع الأوقات بتوقيت GMT +2. الساعة الآن 06:58 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.