Skip to content

Commit 52c2d90

Browse files
committed
貼贴
new file: resistor/CMakeLists.txt new file: resistor/build.sh new file: resistor/include/resistorcal.h new file: resistor/src/main.c new file: resistor/src/resistorcal.c new file: ../go/r/01/main.go
1 parent 238a699 commit 52c2d90

File tree

6 files changed

+82
-0
lines changed

6 files changed

+82
-0
lines changed

c/resistor/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CMAKE_MINIMUM_REQUIRED(VERSION 2.9)
2+
PROJECT(RESISTOR)
3+
INCLUDE_DIRECTORIES(./include)
4+
AUX_SOURCE_DIRECTORY(./src DIR_SRC)
5+
ADD_EXECUTABLE(./bin ${DIR_SRC})

c/resistor/build.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
rm -rf build
3+
mkdir build
4+
cd build
5+
cmake .. -G "MinGW Makefiles"
6+
make
7+
./bin

c/resistor/include/resistorcal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#ifndef _RESISTOR_H
2+
#define _RESISTOR_H
3+
double resistorcal(double R1,double R2,char type);
4+
#endif

c/resistor/src/main.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <stdio.h>
2+
#include "../include/resistorcal.h"
3+
int main(){
4+
printf("Welcome to Mayuri's Resistor Calculator(Only for separate routes and 2 resistor in it)\n");
5+
printf("Make your choice\n> 1.Your have the two resistors of separate routes\n> 2. Your have one of the resistors in the separate routes and the total resistor\nAny other choice is to exit\n");
6+
char choice;
7+
scanf("%c",&choice);
8+
switch (choice){
9+
case '1' : printf("Please input your args as [R1 R2]:\n");break;
10+
case '2' : printf("Please input your args as [R1 R]:\n");break;
11+
default : printf("exiting\n");return 0;break;
12+
}
13+
double r1 = -1 ,r2 = -1;
14+
scanf("%lf %lf",&r1,&r2);
15+
while ((r1<0)||(r2<0)) {
16+
printf("args don't meet the requirement(R>0)\n");
17+
printf("please input them again:\n");
18+
scanf("%lf %lf",&r1,&r2);
19+
20+
}
21+
switch (choice){
22+
case '1' : printf("R=%lf",resistorcal(r1,r2,choice));break;
23+
case '2' : printf("R2=%lf",resistorcal(r1,r2,choice));break;
24+
}
25+
}

c/resistor/src/resistorcal.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <stdio.h>
2+
#include "../include/resistorcal.h"
3+
double resistorcal(double R1,double R2,char type){
4+
switch (type){
5+
case '1' : return (R1*R2)/(R1+R2); break;
6+
case '2' : return (R1*R2)/(R1-R2); break;
7+
}
8+
}

go/r/01/main.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
)
7+
8+
func main() {
9+
r1 := (flag.Int("r1", -1, "the value of R1"))
10+
r2 := (flag.Int("r2", -1, "the value of R2"))
11+
r := (flag.Int("r", -1, "the value of R"))
12+
flag.Parse()
13+
if (-1 != *r) && (-1 != *r1) && (-1 != *r2) {
14+
fmt.Printf("(R R1)R2=%f\n(R1 R2)R=%f\n", float64((*r1)*(*r))/float64(*r1-*r), float64((*r1)*(*r2))/float64((*r1)+(*r2)))
15+
return
16+
}
17+
if (-1 == *r1) && (-1 != *r2) {
18+
*r1 = *r2
19+
*r2 = -1
20+
}
21+
if -1 == *r1 || ((-1 == *r) && (-1 == *r2)) {
22+
fmt.Printf("plz input args\n")
23+
return
24+
}
25+
if *r != -1 {
26+
fmt.Printf("R2=%f\n", float64((*r1)*(*r))/float64(*r1-*r))
27+
return
28+
}
29+
if *r2 != -1 {
30+
fmt.Printf("R=%f\n", float64((*r1)*(*r2))/float64((*r1)+(*r2)))
31+
return
32+
}
33+
}

0 commit comments

Comments
 (0)