BG Development


  Reply to this topicStart new topicStart Poll

> От C на C++, Преправяне
ilkodim
Публикувано на: 05-11-2020, 17:10
Quote Post



Име:
Група: Потребител
Ранг: Новопостъпил

Мнения: 1
Регистриран на: 04.05.20



Здравейте, може ли някой да обърне този код в c++


CODE
#include<stdio.h>
#include<malloc.h>

struct Room {
  float length;
  float width;
  float squareFootage;
};

void show(struct Room room) {
  printf("\nsquareFootage : %f", room.squareFootage);
  printf("\nLength : %f", room.length);
  printf("\nWidth : %f", room.width);
}

float area(float length, float width) {
  return length * width;
}


int main() {

  int SIZE=0;
  static struct Room* rooms;
 
  printf("\nEnter the number of rooms in the apartment :");
 
  scanf("%d", &SIZE);
 
  rooms = (struct Room*) malloc(SIZE * sizeof(struct Room));
  printf("\nEnter the dimensions for each room :\n");

  for (int i = 0; i < SIZE; i++) {
      printf("\n\nRoom %d dimensions", i + 1);
      printf("\nLength :");
      scanf("%f", &rooms[i].length);
      printf("\nWidth :");
      scanf("%f", &rooms[i].width);

      rooms[i].squareFootage = area(rooms[i].length, rooms[i].width);
  }
  float apartmentSquareFootage = 0.0;
  printf("\nDisplaying apartment details :\n");
  for (int i = 0; i < SIZE; i++) {
      printf("\n\nRoom %d dimensions", i + 1);
      show(rooms[i]);
      apartmentSquareFootage += rooms[i].squareFootage;
  }
  printf("\nApartment square footage :%f", apartmentSquareFootage);

  return 0;
}
PMEmail Poster
Top
DarkOne
Публикувано на: 05-11-2020, 17:47
Quote Post


Group Icon
Име: Александър Петков
Група: Администратор
Ранг: Почетен член

Мнения: 3554
Регистриран на: 30.01.04



Заповядай!
CODE
#include<stdio.h>
#include<malloc.h>

struct Room {
 float length;
 float width;
 float squareFootage;
};

void show(struct Room room) {
 printf("\nsquareFootage : %f", room.squareFootage);
 printf("\nLength : %f", room.length);
 printf("\nWidth : %f", room.width);
}

float area(float length, float width) {
 return length * width;
}


int main() {

 int SIZE=0;
 static struct Room* rooms;

 printf("\nEnter the number of rooms in the apartment :");

 scanf("%d", &SIZE);

 rooms = (struct Room*) malloc(SIZE * sizeof(struct Room));
 printf("\nEnter the dimensions for each room :\n");

 for (int i = 0; i < SIZE; i++) {
     printf("\n\nRoom %d dimensions", i + 1);
     printf("\nLength :");
     scanf("%f", &rooms[i].length);
     printf("\nWidth :");
     scanf("%f", &rooms[i].width);

     rooms[i].squareFootage = area(rooms[i].length, rooms[i].width);
 }
 float apartmentSquareFootage = 0.0;
 printf("\nDisplaying apartment details :\n");
 for (int i = 0; i < SIZE; i++) {
     printf("\n\nRoom %d dimensions", i + 1);
     show(rooms[i]);
     apartmentSquareFootage += rooms[i].squareFootage;
 }
 printf("\nApartment square footage :%f", apartmentSquareFootage);

 return 0;
}


--------------------
The man who learns only what others know
is as ignorant as if he learns nothing.
The treasures of knowledge are the most rare,
and guarded most harshly.
-- Chronicle of the First Age
PMICQ
Top
akrachev
Публикувано на: 05-11-2020, 21:00
Quote Post



Име: акрачев
Група: Потребител
Ранг: Почетен член

Мнения: 935
Регистриран на: 27.11.09



CODE
#include<stdio.h>
#include<iostream>
#include<malloc.h>

struct Room {
float length;
float width;
float squareFootage;
};

void show(struct Room room) {
printf("\nsquareFootage : %f", room.squareFootage);
printf("\nLength : %f", room.length);
printf("\nWidth : %f", room.width);
}

float area(float length, float width) {
return length * width;
}


int main() {

int SIZE=0;
static struct Room* rooms;

cout <<"\nEnter the number of rooms in the apartment :";

cin >> SIZE;

rooms = (struct Room*) malloc(SIZE * sizeof(struct Room));
cout << "\nEnter the dimensions for each room :\n";

for (int i = 0; i < SIZE; i++) {
    cout << "\n\nRoom " << i + 1 << " dimensions";
    cout << "\nLength :";
    cin >> rooms[i].length;
    cout << "\nWidth :";
    cin >> rooms[i].width;

    rooms[i].squareFootage = area(rooms[i].length, rooms[i].width);
}
float apartmentSquareFootage = 0.0;
cout << "\nDisplaying apartment details :\n";
for (int i = 0; i < SIZE; i++) {
    cout << "\n\nRoom " << i + 1 << " dimensions";
    show(rooms[i]);
    apartmentSquareFootage += rooms[i].squareFootage;
}
cout << "\nApartment square footage :%f", apartmentSquareFootage);

return 0;
}


--------------------
PMEmail PosterUsers Website
Top
1 потребители преглеждат тази тема в момента (1 гости, 0 анонимни потребители)
Потребители, преглеждащи темата в момента:

Topic Options Reply to this topicStart new topicStart Poll

 


Copyright © 2003-2019 | BG Development | All Rights Reserved
RSS 2.0