labs 1-6: init

Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
2022-12-24 14:03:08 +05:30
commit ad185c994e
26 changed files with 2250 additions and 0 deletions

80
lab1/1.cpp Normal file
View File

@@ -0,0 +1,80 @@
#include <iostream>
#include <string.h>
class Person {
private:
static const std::size_t MAX_NAME = 30;
static const std::size_t MAX_ADDRESS = 30;
char name[MAX_NAME];
char address[MAX_ADDRESS];
unsigned int age;
float salary;
public:
void getName();
void getAddress();
void getAge();
void getSalary();
void setName(const char[30], size_t);
void setAddress(const char[100], size_t);
void setAge(unsigned int);
void setSalary(float);
};
inline void Person::getName() {
std::cout << name << std::endl;
}
inline void Person::getAddress() {
std::cout << address << std::endl;
}
inline void Person::getAge() {
std::cout << age << std::endl;
}
inline void Person::getSalary() {
std::cout << salary << std::endl;
}
inline void Person::setName(const char name[], size_t size) {
strncpy(this->name, name, (size <= MAX_NAME ? size : MAX_NAME - 1));
if (size > MAX_NAME)
this->name[MAX_NAME - 1] = '\0';
}
inline void Person::setAddress(const char address[], size_t size) {
strncpy(this->address, address, (size <= MAX_ADDRESS ? size : MAX_ADDRESS - 1));
if (size > MAX_NAME)
this->name[MAX_NAME - 1] = '\0';
}
inline void Person::setAge(unsigned int age) {
this->age = age;
}
inline void Person::setSalary(float salary) {
this->salary = salary;
}
int main() {
Person person;
const char name[] = "Retard Singh";
const char address[] = "420 RetardVille";
unsigned int age = 44;
float salary = 4.44;
person.setName(name, sizeof(name));
person.setAddress(address, sizeof(address));
person.setAge(age);
person.setSalary(salary);
person.getName();
person.getAddress();
person.getAge();
person.getSalary();
return 0;
}