Net 25 & 26 CopyConstructor
Net 25 & 26 CopyConstructor
Instance Variables:
MobileBrand:string static
CameraPixels:int static
RAMSize:int static
ROMSize:int static
BatteryCapacity:string static
Name:DisplayInfo
ReturnType:string
AccessModifier:public
return the data of the Mobile
create object for Mobile class pass the values by using constructor and also call
the DisplayInfo method.
User has to enter the values.
-----------------------------------------------------------------------------------
--------------------------------
ANS.....
using System;
namespace test
{
public class Mobile
{
static string MobileBrand;
static int CameraPixels;
static int RAMSize;
static int ROMSize;
static string BatteryCapacity;
public Mobile(string mb, int cp, int rams, int roms, string bc)
{
MobileBrand = mb;
CameraPixels = cp;
RAMSize = rams;
ROMSize = roms;
BatteryCapacity = bc;
}
public string display()
{
return $"\nMobile Brand is: {MobileBrand}\n" + $"CameraPixels is:
{CameraPixels}\n" + $"RAMSize is: {RAMSize}\n" + $"ROMSize is: {ROMSize}\n" +
$"BatteryCapacity: {BatteryCapacity}\n ";
}
}
Console.Write(obj.display());
Console.ReadLine();
}
}
}
-----------------------------------------------------------------------------------
----------------------------------------
Instance Variables:
id:int
name:string
salary:double
MethodName:getDetails
returntype:string
accessmodifier:public
return all the data of employee in string format.
Create another class EmployeeDetails
create object for Employee class pass the values by using constructor and also call
the tax method after that display all the data of employee from getDetails method.
User has to enter the values.
-----------------------------------------------------------------------------------
----------------------------------------
ANS.....
using System;
namespace test
{
class Employee
{
int id;
string name;
double salary;
Console.WriteLine(emp.getdetails());
Console.ReadLine();
}
}
}
===================================================================================
==============================
Instance Variables:
SimNumber:long
SimType:string
Name:DisplayInfo
Methods:
Name:DisplayInfo
ReturnType:string
AccessModifier:public
return the data of the Sim
If you change the sim type for example before simtype is airtel and changed to jio
update the simtype
MethodName:UpdateSimtype
Prameters:NewSimType (string)
Returntype:void
AccessModifier:public
update the simtype.
create object for Sim class pass the values by using constructor and also call the
UpdateSimtype method.
Display the siminformation using copy constructor and also display details after
update
copy constructor details don't has to change it should be having old details
User has to enter the values.
#include <stdio.h>
#include <stdlib.h>
if (k == 0) {
for (int i = 0; i < n; i++) {
result[i] = 0;
}
return;
}
if (k > 0) {
int wsum = 0;
for (int i = 1; i <= k; i++) {
wsum += code[i];
}
result[0] = wsum;
k = -k;
int wsum = 0;
for (int i = n - k; i < n; i++) {
wsum += code[i];
}
result[0] = wsum;
int main() {
int n, k;
decrypt(code, n, k, result);
free(code);
free(result);
return 0;
}