CS304 Assignment 1 Solution
#1
Here is the solution for CS304 Asignment 1 spring 2016

Please do not copy. Its for understanding purpose only, you can ask me if you have any questions.
Code:
#include <iostream>
#include <string>
using namespace std;

class Parcel
{
    private:
        int Id;
        string SenderName;
        string SenderAddress;
        string receiverName;
        string receiverAddress;
        int Weight;
        int Fee;
    public:
        //Default Constructor
        Parcel(){
            Id = 0;
            Weight = 0;
            Fee = 0;
        }
        
        //Destructor
        ~Parcel(){
        }
        
        //Setters
        void setId(int x){
            
            Id = x;
        }
        void setSenderName(char* name1){
            SenderName = name1;
        }
        void setSenderAddress(char* add1){
            SenderAddress = add1;
        }
        void setReceiverName(char* name2){
            receiverName = name2;
        }
        void setReceiverAddress(char* add2){
            receiverAddress = add2;
        }
        void setWeight(int w){
            Weight = w;
        }
        void setFee(int f){
            Fee = f;
        }
        
        //Getters
        int getId(){
            return Id;
        }
        string getSenderName(){
            return SenderName;
        }
        string getSenderAdd(){
            return SenderAddress;
        }
        string getReceiverName(){
            return receiverName;
        }
        string getReceiverAdd(){
            return receiverAddress;
        }
        int getWeight(){
            return Weight;
        }
        int getFee(){
            return Fee;
        }
        
        
};

int main()
{
    int id, fee, weight;
    char senderName[50];
    char senderAdd[100];
    char receiverName[50];
    char receiverAdd[100];
    
    Parcel parcel1;
    
    //Getting values from user and saving in the class using Setters
    
    cout<<" Enter receipt No. : ";
    cin>> id;
    parcel1.setId(id);
    cout<<endl;
    
    cout<<" Enter Sender Name : ";
    cin.ignore();
    cin.getline(senderName, sizeof(senderName));
    parcel1.setSenderName(senderName);
    cout<<endl;
    
    cout<<" Enter Sender Address : ";
    cin.getline(senderAdd, sizeof(senderAdd));
    parcel1.setSenderAddress(senderAdd);
    cout<<endl;
    
    cout<<" Enter Receiver Name : ";
    cin.getline(receiverName, sizeof(receiverName));
    parcel1.setReceiverName(receiverName);
    cout<<endl;
    
    cout<<" Enter Receiver Address : ";
    cin.getline(receiverAdd, sizeof(receiverAdd));
    parcel1.setReceiverAddress(receiverAdd);
    cout<<endl;
    
    cout<<" Enter weight(in grams) of the parcel : ";
    cin>> weight;
    parcel1.setWeight(weight);
    cout<<endl;
    
    cout<<" Enter shipment charges : ";
    cin>> fee;
    parcel1.setFee(fee);
    cout<<endl;
    cout<<endl;
    
    //Displaying info using Getters
    cout << "Shipment Receipt";
    cout << "\n---------------------------";
    cout << "\n Receipt No. : " << parcel1.getId();
    cout << "\n Sender Name : " << parcel1.getSenderName();
    cout << "\n Sender Address : " << parcel1.getSenderAdd();
    cout << "\n Receiver Name : " << parcel1.getReceiverName();
    cout << "\n Receiver Address : " << parcel1.getReceiverAdd();
    cout << "\n Parcel Weight (in grams) : " << parcel1.getWeight();
    cout << "\n Shipment Charges : " << parcel1.getFee();

    return 0;

}
#2
(05-17-2016, 03:09 PM)Rana Wrote: Here is the solution for CS304 Asignment 1 spring 2016

Please do not copy. Try to understand and then make yours, if you have any question, you can ask in the comments. 
Code:
#include <iostream>
#include <string>
using namespace std;

class Parcel
{
    private:
        int Id;
        string SenderName;
        string SenderAddress;
        string receiverName;
        string receiverAddress;
        int Weight;
        int Fee;
    public:
        //Default Constructor
        Parcel(){
            Id = 0;
            Weight = 0;
            Fee = 0;
        }
        
        //Destructor
        ~Parcel(){
        }
        
        //Setters
        void setId(int x){
            
            Id = x;
        }
        void setSenderName(char* name1){
            SenderName = name1;
        }
        void setSenderAddress(char* add1){
            SenderAddress = add1;
        }
        void setReceiverName(char* name2){
            receiverName = name2;
        }
        void setReceiverAddress(char* add2){
            receiverAddress = add2;
        }
        void setWeight(int w){
            Weight = w;
        }
        void setFee(int f){
            Fee = f;
        }
        
        //Getters
        int getId(){
            return Id;
        }
        string getSenderName(){
            return SenderName;
        }
        string getSenderAdd(){
            return SenderAddress;
        }
        string getReceiverName(){
            return receiverName;
        }
        string getReceiverAdd(){
            return receiverAddress;
        }
        int getWeight(){
            return Weight;
        }
        int getFee(){
            return Fee;
        }
        
        
};

int main()
{
    int id, fee, weight;
    char senderName[50];
    char senderAdd[100];
    char receiverName[50];
    char receiverAdd[100];
    
    Parcel parcel1;
    
    //Getting values from user and saving in the class using Setters
    
    cout<<" Enter receipt No. : ";
    cin>> id;
    parcel1.setId(id);
    cout<<endl;
    
    cout<<" Enter Sender Name : ";
    cin.ignore();
    cin.getline(senderName, sizeof(senderName));
    parcel1.setSenderName(senderName);
    cout<<endl;
    
    cout<<" Enter Sender Address : ";
    cin.getline(senderAdd, sizeof(senderAdd));
    parcel1.setSenderAddress(senderAdd);
    cout<<endl;
    
    cout<<" Enter Receiver Name : ";
    cin.getline(receiverName, sizeof(receiverName));
    parcel1.setReceiverName(receiverName);
    cout<<endl;
    
    cout<<" Enter Receiver Address : ";
    cin.getline(receiverAdd, sizeof(receiverAdd));
    parcel1.setReceiverAddress(receiverAdd);
    cout<<endl;
    
    cout<<" Enter weight(in grams) of the parcel : ";
    cin>> weight;
    parcel1.setWeight(weight);
    cout<<endl;
    
    cout<<" Enter shipment charges : ";
    cin>> fee;
    parcel1.setFee(fee);
    cout<<endl;
    cout<<endl;
    
    //Displaying info using Getters
    cout << "Shipment Receipt";
    cout << "\n---------------------------";
    cout << "\n Receipt No. : " << parcel1.getId();
    cout << "\n Sender Name : " << parcel1.getSenderName();
    cout << "\n Sender Address : " << parcel1.getSenderAdd();
    cout << "\n Receiver Name : " << parcel1.getReceiverName();
    cout << "\n Receiver Address : " << parcel1.getReceiverAdd();
    cout << "\n Parcel Weight (in grams) : " << parcel1.getWeight();
    cout << "\n Shipment Charges : " << parcel1.getFee();

    return 0;

}
#3
hmmmmmmmmmmmmmmmm welldone
#4
(05-20-2016, 12:02 AM)Waryam Choudhry Wrote: hmmmmmmmmmmmmmmmm welldone

Thank you.
  


Possibly Related Threads...
Thread Author Replies Views Last Post
  CS304 GDB Solution Pakistani 2 968 07-28-2017, 07:54 AM
Last Post: Rana
  CS604 Assignment 3 Solution Pakistani 2 260 07-26-2017, 06:17 PM
Last Post: Rubaisha(Moody Girl)
  CS507 Assignment solution Rubaisha(Moody Girl) 0 170 07-25-2017, 10:23 PM
Last Post: Rubaisha(Moody Girl)
  CS601 Assignment 4 Solution Rana 0 503 07-24-2017, 11:49 AM
Last Post: Rana
  CS401 Assignment 3 Solution Pakistani 0 302 07-21-2017, 01:34 PM
Last Post: Pakistani
  CS504 Assignment 3 Rana 7 1,019 07-19-2017, 08:06 AM
Last Post: Rana
  CS502 Assignment 3 Solution Pakistani 0 326 07-18-2017, 10:00 AM
Last Post: Pakistani
  CS605 assignment-3 Solution Nadeem Rana vu 1 211 07-14-2017, 05:49 PM
Last Post: Pakistani
  CS601 Assignment 3 Solution Pakistani 2 406 07-13-2017, 10:57 AM
Last Post: Rana
  cs 601 Assignment Sadaf Afzal 2 265 07-11-2017, 11:13 AM
Last Post: Pakistani



Users browsing this thread:
1 Guest(s)